note 24281 deleted from function.str-replace by felipe
| From: | felipe@php.net | Date: | Sun, 23 Mar 2008 23:03:17 +0000 |
| Subject: | note 24281 deleted from function.str-replace by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137413@lists.php.net to get a copy of this message | ||
Note Submitter: unleadedis at optusnet dot com dot au dot nospam
----
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,
<?php
// 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);
}
?>