Board index   FAQ   Search  
Register  Login
Board index php forum :: Bar Free time

Stupid PHP tricks

Bar discussions . Talk about everything not only php !. Guests are welcome here , forum registration is not required.

Moderators: macek, egami, gesf

Stupid PHP tricks

Postby swirlee » Sat Apr 03, 2004 12:55 am

So I was just in the middle of coding (mostly playing with the wonderful patTemplate and patForms) and came up with this wonderful line of code:
[php]echo $step1vals_encoded = custom_encode($step1vals_array), ' : ', strlen($step1vals_encoded);[/php]
Maybe it's just because it's late, but I'm just tickled at this line. Not only did I make an assignment within an echo statement, I put another statement after it using echo's seldom-used (but faster-than-dot-concatenation) comma syntax (which I always forget to use). Granted, this is only debug code that I'm gonna scrap anyway, but I thought it was nice.

I want to hear about everybody else's late-night bizarro hacks. What's the worst line of code that you're the most proud of?
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby swirlee » Sat Apr 03, 2004 1:00 am

By the way, if you're wondering what custom_encode() does, it's a wee function I wrote to serialize and then encode form data so it can be passed onto a second page in a somewhat difficult-to-mess-with way. Here's the source to it and its sister function:
[php]function custom_encode($var) {
return base64_encode(gzdeflate(serialize($var), ENCODE_LEVEL));
}

function custom_decode($string) {
return unserialize(gzinflate(base64_decode($string), ENCODE_LEVEL));
}[/php]
ENCODE_LEVEL is a constant set by me (see the gzdeflate docs).
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Guest » Wed Apr 07, 2004 10:51 pm

:oops: :offtopic: :drunk: :whistling:
Guest
 


Return to Free time

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron