Monthly Archives: November 2008

Formatted print_r is Darn useful

Here is one of the little improvements upon a php script that makes it even more useful – at least appropriate for browser output. I make no claim to having invented this, its just a useful little script to pass on for debugging arrays in PHP.

function printR($arr, $label= null) {
if($label){
echo “<h2>$label</h2> \n “;
}
echo “\n\n<pre>\n”;
print_r($arr);
echo “\n</pre>\n\n”;
}

Edit a line in all php files in a directory with find and sed

Here is about the simplest example I could come up with, to change a reference to a new include directory location in a codebase.

You can of course do fancier things should you wish to dump your results to a directory before overwriting your files.

#!/bin/sh
for files in `find *.php`
do
sed ‘s/..\/..\/adminincl/includes/g’ $files > ‘temp’.$files && mv ‘temp’.$files $files
done