RE: [PHP] Search replace text

2001-02-13 Thread PHPBeginner.com

ok, here's a scratch:

$contents = file ($file);
for($i=0; $isizeof($contents); $i++){
$staff .= eregi_replace("this", "with_this", $staff);
}

$fp = fopen ($file, "w");
$fputs ($staff);
fclose ($fp);


I think this should work ...


Sincerely,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com





-Original Message-
From: CDitty [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 13, 2001 3:29 AM
To: PHPBeginner.com
Subject: RE: [PHP] Search  replace text


Thanks for the idea.  Can you give me an example of how to load a file into
an array?  My efforts failed.

Thanks

At 03:41 AM 2/12/01, you wrote:
instead of writing to you the code I'll give you an idea:

1. you open the file and read it line-by-line assigning it to an array,
2. you loop that array parsing it line by line changing it's values with
RegEx the way you want.
3. you open the same file and, looping the array writing it down overriding
any existing data in the file.

You are now set.


Sincerely,

  Maxim Maletsky
  Founder, Chief Developer

  PHPBeginner.com (Where PHP Begins)
  [EMAIL PROTECTED]
  www.phpbeginner.com




-Original Message-
From: CDitty [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 12, 2001 5:12 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Search  replace text


Hello all.  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 = "[EMAIL PROTECTED]";
$newemail = "[EMAIL PROTECTED]";
$user = "cditty";
$file = fopen("/path/to/the/user/file/$user.dat", "r");
if(!$file){
  echo "pUnable to open remote file.\n";
  exit;
}else{
  echo "Successbr";
}
while (!feof($file)) {
  $line = fgets($file, 255);
  if(eregi($oldemail, $line, $out)) {
  str_replace($oldemail, $newemail, $line);
  }

echo $line . "BR";
}
fclose($file)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Search replace text

2001-02-13 Thread PHPBeginner.com

Sorry, I made a small mistake in my code ...

this is correct:

$contents = file ($file);
for($i=0; $isizeof($contents); $i++){
$staff .= eregi_replace("this", "with_this", $contents[$i]);
}

$fp = fopen ($file, "w");
$fputs ($staff);
fclose ($fp);


Sincerely,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com





-Original Message-
From: PHPBeginner.com [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 13, 2001 11:34 PM
To: PHP; CDitty
Subject: RE: [PHP] Search  replace text


ok, here's a scratch:

$contents = file ($file);
for($i=0; $isizeof($contents); $i++){
$staff .= eregi_replace("this", "with_this", $staff);
}

$fp = fopen ($file, "w");
$fputs ($staff);
fclose ($fp);


I think this should work ...


Sincerely,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com





-Original Message-
From: CDitty [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 13, 2001 3:29 AM
To: PHPBeginner.com
Subject: RE: [PHP] Search  replace text


Thanks for the idea.  Can you give me an example of how to load a file into
an array?  My efforts failed.

Thanks

At 03:41 AM 2/12/01, you wrote:
instead of writing to you the code I'll give you an idea:

1. you open the file and read it line-by-line assigning it to an array,
2. you loop that array parsing it line by line changing it's values with
RegEx the way you want.
3. you open the same file and, looping the array writing it down overriding
any existing data in the file.

You are now set.


Sincerely,

  Maxim Maletsky
  Founder, Chief Developer

  PHPBeginner.com (Where PHP Begins)
  [EMAIL PROTECTED]
  www.phpbeginner.com




-Original Message-
From: CDitty [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 12, 2001 5:12 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Search  replace text


Hello all.  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 = "[EMAIL PROTECTED]";
$newemail = "[EMAIL PROTECTED]";
$user = "cditty";
$file = fopen("/path/to/the/user/file/$user.dat", "r");
if(!$file){
  echo "pUnable to open remote file.\n";
  exit;
}else{
  echo "Successbr";
}
while (!feof($file)) {
  $line = fgets($file, 255);
  if(eregi($oldemail, $line, $out)) {
  str_replace($oldemail, $newemail, $line);
  }

echo $line . "BR";
}
fclose($file)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Search replace text

2001-02-12 Thread PHPBeginner.com

instead of writing to you the code I'll give you an idea:

1. you open the file and read it line-by-line assigning it to an array,
2. you loop that array parsing it line by line changing it's values with
RegEx the way you want.
3. you open the same file and, looping the array writing it down overriding
any existing data in the file.

You are now set.


Sincerely,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com




-Original Message-
From: CDitty [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 12, 2001 5:12 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Search  replace text


Hello all.  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 = "[EMAIL PROTECTED]";
$newemail = "[EMAIL PROTECTED]";
$user = "cditty";
$file = fopen("/path/to/the/user/file/$user.dat", "r");
if(!$file){
 echo "pUnable to open remote file.\n";
 exit;
}else{
 echo "Successbr";
}
while (!feof($file)) {
 $line = fgets($file, 255);
 if(eregi($oldemail, $line, $out)) {
 str_replace($oldemail, $newemail, $line);
 }

echo $line . "BR";
}
fclose($file)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Search replace text

2001-02-12 Thread Christian Reiniger

On Monday 12 February 2001 01:22, David Robley wrote:
  while (!feof($file)) {
   $line = fgets($file, 255);
   if(eregi($oldemail, $line, $out)) {
   str_replace($oldemail, $newemail, $line);

 You need to assign the output of this function to a string:
$new_line = str_replace($oldemail, $newemail, $line);

Another little thing: You don't need the eregi() here - just do 
str_replace. If it doesn't find $oldemail it won't do anything.

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

Nothing is more dangerous than an idea if it's the only one you have.

- Emil-Auguste Chartier, "Propos sur la religion", 1938

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Search replace text

2001-02-11 Thread CDitty

Hello all.  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 = "[EMAIL PROTECTED]";
$newemail = "[EMAIL PROTECTED]";
$user = "cditty";
$file = fopen("/path/to/the/user/file/$user.dat", "r");
if(!$file){
 echo "pUnable to open remote file.\n";
 exit;
}else{
 echo "Successbr";
}
while (!feof($file)) {
 $line = fgets($file, 255);
 if(eregi($oldemail, $line, $out)) {
 str_replace($oldemail, $newemail, $line);
 }

echo $line . "BR";
}
fclose($file)


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Search replace text

2001-02-11 Thread David Robley

On Mon, 12 Feb 2001 06:41, CDitty wrote:
 Hello all.  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 = "[EMAIL PROTECTED]";
 $newemail = "[EMAIL PROTECTED]";
 $user = "cditty";
 $file = fopen("/path/to/the/user/file/$user.dat", "r");
 if(!$file){
  echo "pUnable to open remote file.\n";
  exit;
 }else{
  echo "Successbr";
 }
 while (!feof($file)) {
  $line = fgets($file, 255);
  if(eregi($oldemail, $line, $out)) {
  str_replace($oldemail, $newemail, $line);

You need to assign the output of this function to a string:
   $new_line = str_replace($oldemail, $newemail, $line);

  }

 echo $line . "BR";

and then

echo $new_line . 'BR;

 }
 fclose($file)

-- 
David Robley| WEBMASTER  Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES  | http://www.nisu.flinders.edu.au/
AusEinet| http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]