note 14826 deleted from function.array-pad by irc-html

From: Date: Sat, 19 Jan 2002 21:07:14 +0000
Subject: note 14826 deleted from function.array-pad by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-25471@lists.php.net to get a copy of this message
Moving a file from a PHP4.0.5 system to a PHP4.0.4 system, I discovered that I couldn't pass arrays to str_replace, so I rolled my own str_replace function... function tom_str_replace ($searcharray,$replace,$haystack) { settype ($searcharray, "array"); if (is_array($replace)) { $replacearray=array_pad($replace,count($searcharray),""); } else { settype ($replace, "array"); $replacearray=array_pad($replace,count($searcharray),$replace[0]); } reset($replacearray); $replacestring=current($replacearray); foreach($searcharray as $search) { $haystack=str_replace($search,$replacestring,$haystack); $replacestring=next($replacearray); } return $haystack; }

« previous php.notes (#25471) next »