note 15531 deleted from function.str-replace by didou

From: Date: Sat, 16 Aug 2003 09:54:30 +0000
Subject: note 15531 deleted from function.str-replace by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54320@lists.php.net to get a copy of this message
Note Submitter: webmaster@zeek4.com ---- ok heres what i discovered, maybe its not new to u but here goes: srt_replace() doesnt replace too long strings at least not directly. the max string size is probably 329 (tested on strpos()) but it seems that the max string size doesnt apply to array values aquired from a database (substitutes about 500 in length strings with no prob). heres the solutiuon: $replacable = "a string with x length"; if(strlen($replacable) > 329) { $start = strpos($haystack, substr($replacable, 0, 329)); $end = $start + strlen($replacable); $new_haystack = substr($haystack, 0, $start).substr($haystack, $end-1); } else { $new_haystack = str_replace($replacable, " ", $haystack); }

« previous php.notes (#54320) next »