Along the same lines of my previous post, I was looking for a PHP equivalent to Data::Dumper for Perl. Php has a builtin function called var_dump() which will give you some fairly ugly output about your array/hash/object, however I was looking for something a little more elegant.Thankfully the folks over at Pear have come up with a very nice alternative. Simply install the Var_Dump PEAR module and then do:
Alternative you can use the excellent built-in PHP function print_r() which does the same as Var_Dump without all the extra information included:
I’ve been writing Perl code since just after I learned to walk, so I’m always looking for ways to do things in a Perl-ish manner. My latest requirement was an equivalent to the perl chop() command to remove the last character of a string for PHP. After a bit of searching around, it appears the best way to do this is:
$string = substr($string, 0, -1);
This method avoids unnecessary interpolation overheads (apparently)!
my_field_124 => my_field
fieldName.replace (/\_\d+/, '');
What I thought would display is the string “my_field”. Instead I kept getting “my_field_1” returned. The reason for this is that the replace() function returns the resulting value, and doesn’t change the value of the original string! Change the script to:
And it works!
I setup auto-forwarding for a client’s Gmail account today and ran into a couple of interesting problems. Firstly, I tested the auto-forwarding function from my own Gmail account, with the forwarding email address set to my own Gmail account. After a number of attempts, i discovered that i wasn’t receiving the forwarded emails.
After playing around a bit, I discovered that the forwarded emails worked fine as long as I didn’t have the forwarding address set to the same as the address I was sending the test emails from. After sending a test email from a different account, the forwarding worked fine. Lesson: don’t try and test Gmail auto-forwarding by sending an email from the address you are forwarding back to!