Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit/append a file

Status
Not open for further replies.

qwicker

Programmer
Feb 16, 2005
12
0
0
US
Hello,
What i need to do is edit a text file. I have input in the file like this:

text1
*text2
text3
*text4
text5

What i need to do is remove that asteric(*) from *text4. I do NOT want to remove the asteric from *text2. How do i do this? i assume fopen($filename 'a'); but what would the syntax of removing that asteric be? Im thinking i need to "find" *text4, then somehow delete the 1st character on that line. I appreciate any and all comments/responses
 
<?php
//open and read all the file
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
//replace *text4 to text4
$new_contents = str_replace("*text4", "text4", $contents);
//Write the file
$handle = fopen($filename, 'w');
fwrite($handle, $new_contents);
fclose($handle);
?>


hope this will work :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top