Page 1 of 1
eregi_replace() function
Posted: Wed Mar 02, 2005 12:57 am
by husniteja
i tried to figure out what the meaning of {script} with this code :
Code: Select all
eregi_replace("\{script\}", $HTTP_SERVER_VARSї"SCRIPT_NAME"], $content);
i read the manual that that {script} will be changed with the $HTTP_SERVER_VARS["SCRIPT_NAME"], but i don't know what is script mean
Posted: Wed Mar 02, 2005 1:17 am
by n00b Saibot
its just replacing "{script}" with page/script/file name.
Posted: Wed Mar 02, 2005 2:29 am
by husniteja
hi
i tried to echo both condition, first before eregi_replace and after eregi_replace
but there is nothing change, what is it mean ? as i told you before in the manual said the second string will replace the first string. But in the $content there is no string "script" so what do they do to change ?
do you simple sampel for this ?
Posted: Wed Mar 02, 2005 3:48 am
by n00b Saibot
if it finds the string {script} in your $content string then only it will change it.
otherwise it just leaves it as is.
For e.g.
Code: Select all
<?php
$mystr = 'I have {item}.';
$newstr = eregi_replace('\{item\}', 'an Apple', $mystr);
print $mystr.'<br>'.$newstr; //first change.
$newstr = eregi_replace('\{item\}', 'the Power', $mystr);
print $mystr.'<br>'.$newstr; //second change.
?>
EDIT: I forgot to mention it that using preg_replace is faster the eregi_replace and its use instead is recommended.