791Combining stderr and stdout 2>&1

If you ever find yourself in a situation of having to call a perl script from within PHP, and you want to get the return values from the perl script, you might do it like the following:

$command = "perl /my/perl/script.pl";
$results = exec($command);
// does not print error

If the perl script generates error, you won’t be able to see them, as they are written to stderr.

One solution might be to append the stderr to stdout, therefore getting it into the $results variable.

$command = "perl /my/perl/script.pl 2>&1";
$results = exec($command);
// Prints: Died at /my/perl/script.pl line 25.

As this post explains, 1 means stdout, 2 means stderr. 2>1 might look ok at first sight, but the ’1′ will be interpreted as a filename. Therefore it has to be escaped with &1, resulting in 2>&1.

682Remove empty array fields in PHP

array_filter($my_array)

array_filter WITHOUT a callback function removes ‘false’, ‘null’ and ” fields from an array.

652PHP Arrays to Javascript Objects via JSON

Moving PHP Associative Array (Dictionaries, whatever..) over for use in Javascript. In JS Associative Array are actually objects, so we might as well make it into one.

echo "var data =" . json_encode($somatic, JSON_FORCE_OBJECT) . ";

565Stripping Characters from an NSString

NSString *stripped = [unstripped stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\n\t "]];

Well, Cocoa, a bit of too much syntactic nutrasweet here. Take a look at PHP and wheep:

$stripped = trim($unstripped);

(Yes, I am aware that’s somewhat of an unfair comparion, but still…)

319Chaning Colors in Twitter with the API

require "<a href="http://github.com/jdp/twitterlibphp">twitter.lib.php</a>";
 
$username = "<a href="http://twitter.com/trembl/">trembl</a>";
$password = "&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;";
 
$twitter = new Twitter($username, $password);
 
$options = array(
	"profile_background_color" => "fff",
	"profile_text_color" => "fff",
	"profile_link_color" => "fff",
	"profile_sidebar_fill_color" => "fff",
	"profile_sidebar_border_color" => "fff"
);
 
$update_response = $twitter->updateProfileColors($options);
print_r($update_response);

Nice, isn’t it?

265Like explode(), only componentsSeparatedByString:

PHP
explode(“, ” , “One, Two, Three”);

Objective-C
NSArray *listItems = [@"One, Two, Three" componentsSeparatedByString:@", "];

98PHP-cgi wrapper

http://wordpress.org/support/topic/217411

http://www.pair.com/support/knowledge_base/authoring_development/system_cgi_php-cgiwrap.html

85Calling ImageMagick from PHP

Getting ImageMagick to work by calling system() in PHP turned out to be more troublesome that originally assumed. Of course, Safe-Mode has be off, the dirs need to have the appropriate permission, and the absolute paths to ‘convert’ and your files should be set.

But still, it would not work. Despite executing directly in the shell quite nicely. The revelation came late, but better than never:

IM apparently hate single quote ‘ ‘, and absolutely insists on double quotes ” ” to wrap it’s arguments in.

Can not really say, that this is well thought out… Anyways…