Connecting Tech Pros Worldwide Help | Site Map

str_replace - Modify external file?

  #1  
Old March 14th, 2008, 05:55 PM
jfcby
Guest
 
Posts: n/a
Hello,

My data.txt file is formated like this:

qqqq||eeee
rrrr||tttt
yyyy||uuuu
iiii||oooo
aaaa||bbbb

I'm trying to get this code to replace the data I put in $name but it
is not changing.

How can the php code be changed to modify the data I put in $name?

<?php
$name = "aaaa"
if(is_writable("data.txt"))
{
$fp = fopen("data.txt","a");
$content = $fp;
$rplName = str_replace("aaaa","TestRpl",$content);
fwrite($fp, $rplName);
fclose($fp);
}
else
{
echo'File is not writable';
}
?>

Thank you for your help,
jfcby
  #2  
Old March 14th, 2008, 06:05 PM
Robin
Guest
 
Posts: n/a

re: str_replace - Modify external file?


jfcby wrote:
Quote:
Hello,
>
My data.txt file is formated like this:
>
qqqq||eeee
rrrr||tttt
yyyy||uuuu
iiii||oooo
aaaa||bbbb
>
I'm trying to get this code to replace the data I put in $name but it
is not changing.
>
How can the php code be changed to modify the data I put in $name?
>
<?php
$name = "aaaa"
if(is_writable("data.txt"))
{
$fp = fopen("data.txt","a");
$content = $fp;
$rplName = str_replace("aaaa","TestRpl",$content);
fwrite($fp, $rplName);
fclose($fp);
}
else
{
echo'File is not writable';
}
?>
>
Thank you for your help,
jfcby

The first user contribution at
http://uk2.php.net/manual/en/function.fopen.php
does what you want.

Robin
  #3  
Old March 14th, 2008, 06:45 PM
Damodhar
Guest
 
Posts: n/a

re: str_replace - Modify external file?


$filename = "data.txt";

$handle = fopen($filename,'r');
$content = fread($handle,filesize($filename));
echo $content;
$name = str_replace("aaa","TestRpl",$content);
fclose($handle);
if ($name)
{
$handle = fopen($filename,'w');
fwrite($handle,$name);
fclose($handle);

}

can u use it.... u want like this..
  #4  
Old March 14th, 2008, 07:15 PM
jfcby
Guest
 
Posts: n/a

re: str_replace - Modify external file?


Hello Robin,

Thank you for the link below! I've been searching Google now for about
3 weeks for a solution and did not find one.
Quote:
The first user contribution athttp://uk2.php.net/manual/en/function.fopen.php
does what you want.
Thank you for your help,
jfcby
  #5  
Old March 14th, 2008, 07:25 PM
jfcby
Guest
 
Posts: n/a

re: str_replace - Modify external file?


Hello Damodhar,

Thank you for the modified code.
Quote:
$filename = "data.txt";
>
$handle = fopen($filename,'r');
$content = fread($handle,filesize($filename));
echo $content;
$name = str_replace("aaa","TestRpl",$content);
fclose($handle);
if ($name)
{
* * * * $handle = fopen($filename,'w');
* * * * fwrite($handle,$name);
* * * * fclose($handle);
>
}
But why did you say that:
Quote:
u want like this..
Thank you for your help,
jfcby

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
include file and variable Bob Bedford answers 3 August 6th, 2007 06:05 PM
HTTP problem, wrong characters sent (HTTP pro's needed!) webEater answers 3 September 28th, 2006 05:05 AM
str_replace() external file The Numerator answers 4 July 29th, 2006 12:05 AM
fyi - combination of outlook and php - create stationery for MS outlook using PHP engine ;-) windandwaves answers 6 March 22nd, 2006 10:15 PM
Including html files David Johnson answers 18 July 17th, 2005 07:44 AM