note 15531 added to function.str-replace
| From: | webmaster at zeek4 dot com | Date: | Sun, 16 Sep 2001 00:07:50 +0000 |
| Subject: | note 15531 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18051@lists.php.net to get a copy of this message | ||
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);
}
http://www.php.net/manual/en/function.str-replace.php