note 86757 deleted from function.str-replace by danbrown

From: Date: Sun, 02 Nov 2008 14:47:02 +0000
Subject: note 86757 deleted from function.str-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146044@lists.php.net to get a copy of this message
Note Submitter: luruke ---- My str_replace() implementation: <?php function replace($search, $replace, $subject){ $subject .= " "; for($temp="",$array=array(),$j=0,$i=0;$i<strlen($subject);$i++){ if($subject{$i} <> " "){ $temp .= $subject{$i}; } else { $array[$j] = $temp; $j++; $temp = ""; } } for($i=0;$i<count($array);$i++) if($array[$i] == $search) $array[$i] = $replace; for($res="",$i=0;$i<count($array);$i++) if($i<count($array)-1) $res .= $array[$i]." "; else $res .= $array[$i]; return $res; } print replace("blacklight", "luruke", "blacklight e' hacker"); ?>

« previous php.notes (#146044) next »