note 12269 deleted from function.print-r by philip

From: Date: Tue, 04 Dec 2001 02:24:19 +0000
Subject: note 12269 deleted from function.print-r by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-21587@lists.php.net to get a copy of this message
Sorry to all people who had problems with print_rrr. There is a bug about quotes (" and '). function print_rrr($name,$element,$level){ if(is_array($element)) { $res=str_repeat("\t",$level).($level? "\t\"".$name.'" => ':'$'.$name.' = ').'array('; $counter=1; reset($element); while(list($key,$val)=each($element)){ $res.="\n".print_rrr($key,$val,$level+1); $res.=($counter==count($element)? '':','); $counter++; } $res.="\n".str_repeat("\t",$level).($level? "\t)":');'); } else $res=str_repeat("\t",$level+1).(is_numeric($name)? $name:'"'.addslashes(stripslashes($name)).'"').' => '.(is_numeric($element)? $element:'"'.addslashes(strislashes($element)).'"'); return $res; } After adding addslashes(stripslashes(..)) it is safe for strings which includes quotes. We must remove slashes and than add them again. In case there are no slashes they are added but next time if we are not using stripslashes we will escape the slashes which we had added.

« previous php.notes (#21587) next »