eregi_replace() function

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

Post Reply
husniteja
Forum Newbie
Posts: 10
Joined: Fri Feb 25, 2005 8:33 pm
Location: south korea

eregi_replace() function

Post 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
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

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 »

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 ?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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 &#123;item&#125;.';
$newstr = eregi_replace('\&#123;item\&#125;', 'an Apple', $mystr);
print $mystr.'<br>'.$newstr; //first change.
$newstr = eregi_replace('\&#123;item\&#125;', '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.
Post Reply