[thelist] Search & replace text

Richard Livsey R.Livsey at cache-22.co.uk
Mon Feb 12 08:15:14 CST 2001


Instead of :

> $oldemail = "email1 at mydomain.com";
> $newemail = "email2 at mydomain.com";

try

$oldemail = 'email1 at mydomain.com';
$newemail = 'email2 at mydomain.com';

It may be parsing the string in the regex - ie the '.'

eregi("email1 at mydomain.com", $line, $out)
is different to
eregi('email1 at mydomain.com', $line, $out)

as these will equate to
eregi("email1 at mydomain[any character]com", $line, $out) // probably not what
you want
eregi('email1 at mydomain.com', $line, $out) // what you want

Hope thats understandable and helps you out!

R.Livsey
Freelance web developer
Vibus.net Director
Lead programmer for Tickle.co.uk
m. +44 (0) 7714 757250
e. R.Livsey at Cache-22.co.uk

> -----Original Message-----
> From: thelist-admin at lists.evolt.org
> [mailto:thelist-admin at lists.evolt.org]On Behalf Of CDitty
> Sent: Sunday, February 11, 2001 10:30 PM
> To: thelist at lists.evolt.org
> Subject: [thelist] Search & replace text
>
>
> I posted this on the PHP list, but haven't had any answers yet.  Anyone
> here know the answer?
>
> I am trying to search through a text file on my server to replace
> the user
> email. I can open the file and read it, but cannot get it to "find" the
> actual string and replace it. Can someone look over my code and see what
> the problem is? I am afraid that ereg is not my strongest point.
> Also, at
> what point should I start writing the file out? Wouldn't there be a
> permissions error if I was reading and writing at the same time?
>
> Thanks
> CDitty
>
> $oldemail = "email1 at mydomain.com";
> $newemail = "email2 at mydomain.com";
> $user = "cditty";
> $file = fopen("/path/to/the/user/file/$user.dat", "r");
> if(!$file){
> echo "<p>Unable to open remote file.\n";
> exit;
> }else{
> echo "Success<br>";
> }
> while (!feof($file)) {
> $line = fgets($file, 255);
> if(eregi($oldemail, $line, $out)) {
> str_replace($oldemail, $newemail, $line);
> }
> echo $line . "<BR>";
> }
> fclose($file)
>
>
>
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt !





More information about the thelist mailing list