PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
husniteja
Forum Newbie
Posts: 10 Joined: Fri Feb 25, 2005 8:33 pm
Location: south korea
Post
by husniteja » Wed Mar 02, 2005 12:57 am
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
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Wed Mar 02, 2005 1:17 am
its just replacing "{script}" with page/script/file name.
husniteja
Forum Newbie
Posts: 10 Joined: Fri Feb 25, 2005 8:33 pm
Location: south korea
Post
by husniteja » Wed Mar 02, 2005 2:29 am
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 ?
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Wed Mar 02, 2005 3:48 am
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.