ThomPorter.com

Welcome to Thom Porter's personal site.

Recent Spam appearing from the thomporter.com domain...

Posted: Oct 08 '07 to SPAM Issues

This post is in response to SPAM that was sent appearing to be from a thomporter.com address. If you received such an email, please read this!

BWF: Bad Word Filter for PHP

Posted: Feb 05 '07 to Programming (PHP, HTML, etc.)

I'm pleased to announce my first open-source project: BWF - Bad Word Filter. If you're a PHP developer worrying about filtering out bad words, you might want to check it out!

Colorful PHP Debugging

Posted: Jan 16 '06 to Programming (PHP, HTML, etc.)

This is a simple little PHP function I created back when I fist came across the var_export() function. It combines it with the power of highlight_string() to bring quick debugging to a new level. I've been using this for years now, but until recently, didn't have this blog. I figured this would a be a good bit of code to start off with:

My printr() function:


<?php
/**
* printr() - Highlights exported variable
*
* @param mixed $var Variable to export
* @param string $name Name of the variable
* @param bool $echo Print or Return it?
* @return mixed
**/
function printr($obj, $name='$obj', $echo = TRUE) {
    
$str = var_export($obj, 1);
    
$str = "<?php\n$name = $str;\n?>\n";
    
$str = highlight_string($str, true);
    
$str = '<pre>' . $str . '</pre>';
    
$str = preg_replace("/<br\s*\\/?>/", "\n", $str);
    if (
$echo) {
        echo
$str;
    } else {
        return
$str;
    }
}

?>


Samples:

Here are some samples of printr()'s output:

Code:


<?php
$a
= Array('PHP','JavaScript','HTML');
printr($a);
?>

Output:


<?php
$obj
= array (

  
0 => 'PHP',
  
1 => 'JavaScript',
  
2 => 'HTML',
);
?>

Code:


<?php
class testClass {
    var
$test1 = 'test1';
    var
$test2 = 'test2';
    var
$test3 = array('a','b');
}
$b = new testClass();
printr($b, '$b');
?>

Output:

<?php
$b = class testclass {

  var
$test1 = 'test1';
  var
$test2 = 'test2';
  var
$test3 =
  array (
    
0 => 'a',

    
1 => 'b',
  );
};
?>


Enjoy! =)
Next

Template/Theme

Choose a Template:
Choose a Theme:

Sponsored Links

RoboForm