note 101250 modified in function.preg-replace by danbrown
| From: | danbrown@php.net | Date: | Mon, 06 Dec 2010 18:00:43 +0000 |
| Subject: | note 101250 modified in function.preg-replace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174668@lists.php.net to get a copy of this message | ||
Just something to have in mind...
When using preg_replace, have in mind that variables are calculated. There is no warning issued if
the variable is not defined, even when error reporting is set to E_ALL ^ E_STRICT
As you can see from the below example:
<?php
$text = 'The price is PRICE ';
$lookFor = 'PRICE';
$replacement = '$100';
echo $replacement.'<br />';
//will display
//$100
echo preg_replace('/'.$lookFor.'/', $replacement, $text).'<br
/>';
//Will display
//The price is 0
echo str_replace($lookFor, $replacement, $text).'<br />';
//Will display
//The price is $100
?>
--was--
/*Just something to have in mind...
When using preg_replace, have in mind that variables are calculated. There is no warning issued if
the variable is not defined, even when error reporting is set to E_ALL ^ E_STRICT
*/
//As you can see from the below example:
///-------------------------------------------------------------
$text = 'The price is PRICE ';
$lookFor = 'PRICE';
$replacement = '$100';
echo $replacement.'<br />';
//will display
//$100
echo preg_replace('/'.$lookFor.'/', $replacement, $text).'<br
/>';
//Will display
//The price is 0
echo str_replace($lookFor, $replacement, $text).'<br />';
//Will display
//The price is $100
///-------------------------------------------------------------
http://php.net/manual/en/function.preg-replace.php