From: Andres Gonzalez on
I have a large C source file that is generated by a separate
source-generating program. When the generated src file is compiled, it
produces tons of warnings. I want to edit the generated src file and
delete the offending lines.

What is the easiest way using a PHP script to read in a file, search for
a particular signature, and delete a couple of lines? Seems like this
would be very easy in PHP.

Thanks,

-Andres
From: Rene Veerman on
On Mon, May 24, 2010 at 11:16 PM, Andres Gonzalez
<andres(a)packetstorm.com> wrote:
> I have a large C source file that is generated by a separate
> source-generating program. When the generated src file is compiled, it
> produces tons of warnings. I want to edit the generated src file and delete
> the offending lines.
>
> What is the easiest way using a PHP script to read in a file, search for a
> particular signature, and delete a couple of lines? Seems like this would be
> very easy in PHP.

file_get_contents() to get the file into a $string.

preg_match_all(,,$matches) to get to what you need,

str_replace() to replace $matches with your chosen replacements

and there you are :)

file_put_contents() to save the results..

>
> Thanks,
>
> -Andres
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
---------------------------------
Greetings from Rene7705,

My free open source webcomponents:
http://code.google.com/u/rene7705/
http://mediabeez.ws/downloads (and demos)

http://www.facebook.com/rene7705
---------------------------------
From: Andres Gonzalez on
thank you Rene, that is the start I needed.

-Andres


Rene Veerman wrote:
> On Mon, May 24, 2010 at 11:16 PM, Andres Gonzalez
> <andres(a)packetstorm.com> wrote:
>
>> I have a large C source file that is generated by a separate
>> source-generating program. When the generated src file is compiled, it
>> produces tons of warnings. I want to edit the generated src file and delete
>> the offending lines.
>>
>> What is the easiest way using a PHP script to read in a file, search for a
>> particular signature, and delete a couple of lines? Seems like this would be
>> very easy in PHP.
>>
>
> file_get_contents() to get the file into a $string.
>
> preg_match_all(,,$matches) to get to what you need,
>
> str_replace() to replace $matches with your chosen replacements
>
> and there you are :)
>
> file_put_contents() to save the results..
>
>
>> Thanks,
>>
>> -Andres
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
>
>
>
>
From: Ryan Sun on
yea, file_get_contents and file_put_contents are the easiest, but play
with caution when dealing with large files, 'cause it loads the whole
file into memory, fopen() fread() fwrite() can be used for large
files.

On Mon, May 24, 2010 at 5:56 PM, Rene Veerman <rene7705(a)gmail.com> wrote:
> On Mon, May 24, 2010 at 11:16 PM, Andres Gonzalez
> <andres(a)packetstorm.com> wrote:
>> I have a large C source file that is generated by a separate
>> source-generating program. When the generated src file is compiled, it
>> produces tons of warnings. I want to edit the generated src file and delete
>> the offending lines.
>>
>> What is the easiest way using a PHP script to read in a file, search for a
>> particular signature, and delete a couple of lines? Seems like this would be
>> very easy in PHP.
>
> file_get_contents() to get the file into a $string.
>
> preg_match_all(,,$matches) to get to what you need,
>
> str_replace() to replace $matches with your chosen replacements
>
> and there you are :)
>
> file_put_contents() to save the results..
>
>>
>> Thanks,
>>
>> -Andres
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
>
> --
> ---------------------------------
> Greetings from Rene7705,
>
> My free open source webcomponents:
>  http://code.google.com/u/rene7705/
>  http://mediabeez.ws/downloads (and demos)
>
> http://www.facebook.com/rene7705
> ---------------------------------
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
From: shiplu on
You can use shell commands.
Like sed, replace etc ..


Shiplu Mokadd.im
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
SUST Programmers, http://groups.google.com/group/p2psust
Innovation distinguishes bet ... ... (ask Steve Jobs the rest)