Wednesday, 3 June 2015

string output formatter

This function is mainly for debugging purposes. Basically it shows where all the newlines, carriage returns, nulls, and tabs are located.

<?php function dump_opt($string$return false){ 
    
$find     =  array("\n",     "\0",     "\t",     "\r"); 
    
$replace  =  array("\n".'\n',"\0".'\0',"\t".'\t',"\r".'\r'); 
    
$string str_replace($find$replace$string); 
    if((bool)
$return) 
        return 
$string; 
    else 
        echo  
$string; 
} 
$string = <<<STR This string has some new lines 
in it 
it may have a carriage return or two as well. 
STR; dump_opt($string); ?>

0 comments:

Post a Comment