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 4 2868
jfcby wrote:
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
$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..
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.
The first user contribution athttp://uk2.php.net/manual/en/function.fopen.php
does what you want.
Thank you for your help,
jfcby
Hello Damodhar,
Thank you for the modified code.
$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:
u want like this..
Thank you for your help,
jfcby This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Igor Shulgin |
last post by:
Hi!
What is standard and direct way (within Oracle 9.2 stored procedures)
for
writing binary data from Oracle to external file on disk?
We have tried to use UTL_FILE package, but it operates on...
|
by: George Ziniewicz |
last post by:
..
I have an html file with javascript functions in the <head> section that
work fine when called from events or instanced as objects.
When I move the functions to an external js file they don't...
|
by: mr_burns |
last post by:
Hi,
i was wondering if it is possible to load text into a string from an
external text file. the reason is that i have a very large string and
it is making my script very messy.
also, is it...
|
by: Hugh Macdonald |
last post by:
I'm writing a tool at the moment that reads in an external file (which
can use any Python syntax)
At the moment, I'm reading the file in using:
scriptLines = open(baseRippleScript).read()...
|
by: Flip |
last post by:
I have a website that's using Master pages (very cool). But when I put JS
on there (to close the browser for example) coming from an external file,
when I navigate away from the first page, the JS...
|
by: teddarr |
last post by:
I'm having trouble reading the first 2 lines of data in an external file.
I am supposed to use a while loop to read the first 2 lines of an external file that contains several random integers. I...
|
by: johanneskrueger |
last post by:
Hello,
I'm currently using <xsl:copy-of select="document(...)/svg:svg"/to
embed an SVG file into an XHTML file. I already defined the SVG
namespace and assigned svg as its prefix in my XSLT 1.0...
|
by: iamdennis |
last post by:
Hi all.
I stuck here and need some help. I have created a combo box which contains a list of links to external PDF files. I also created a OPEN command button next to the combo box. I want to...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |