TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Adding text to a file.. (http://www.talkphp.com/absolute-beginners/2645-adding-text-file.html)

Tanax 04-16-2008 07:30 PM

Adding text to a file..
 
Hey!

I have a file, just a basic .html file.
And I want to open it, scroll down to something that I want to match, and below it add the new data.


So let's say like this:
Code:

customer id: 4
customer mail: gaga@eat.bullshit

---------------
customer id: 5
customer mail: nono@somethings.notright

That's our file.html.
I want to search for "gaga@eat.bullshit" and add below that more content:

Code:

customer id: 4
customer mail: gaga@eat.bullshit
customer name: Tanax
customer location: TalkPHP

---------------
customer id: 5
customer mail: nono@somethings.notright

For example..

How would I accomplish that??
Thanks in advance!

Wildhoney 04-16-2008 10:01 PM

php Code:
function file_intersperse_contents($szFilename, $szAfter, $szInject)
{
    $szContent = file_get_contents($szFilename);
    $szContent = str_replace($szAfter, $szAfter . $szInject, $szContent);
    file_put_contents($szFilename, $szContent);
}

file_intersperse_contents
(
    './file.html',
    'gaga@eat.bullshit',
    "\ncustomer name: Tanax\ncustomer location: TalkPHP"

);

Tanax 04-17-2008 05:25 AM

Thank you! :-D


All times are GMT. The time now is 07:08 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0