note 24281 added to function.str-replace

From: Date: Mon, 12 Aug 2002 04:48:29 +0000
Subject: note 24281 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-34833@lists.php.net to get a copy of this message
The problem is that str_replace seems to call the replace even though there may not be a replacement. This is a problem in that in my parsing script when it finds a certain tag it calls a function, this function does a few SQL queries. It has been noticed that doing a str_replace on a page that contains no 'tag' that I am searching for, the function is called anyway!!! To get around this I have to do a str_pos to see if it exists then call str_replace. eg, // Breadcrumb trail (same as per sitemap) $bc_pos = strpos($string,"[[breadcrumbtrail]]"); if ($bc_pos || is_numeric($bc_pos)) { // true ? then exectue! $string = str_replace ("[[breadcrumbtrail]]", generate_breadcrumb($nodedata_arr, $db), $string); } Grant -- http://www.php.net/manual/en/function.str-replace.php http://master.php.net/manage/user-notes.php?action=edit+24281 http://master.php.net/manage/user-notes.php?action=delete+24281 http://master.php.net/manage/user-notes.php?action=reject+24281

« previous php.notes (#34833) next »