PHP: Replace string in TXT file

This item was filled under [ PHP ]

Ever wanted to search, replace string in TXT files? Use PEAR’s File_SearchReplace and it will do the task for you. You can get a copy of package from: http://pear.php.net/package/File_SearchReplace/

Its quite easy to use. Here is sample code from PEAR’s website:

<?php
include 'File/SearchReplace.php' ;
$files = array( "test1.txt",
"test2.txt",
"test3.txt" ) ;
$ignoreline = array( "#", ":") ;
$snr = new File_SearchReplace( "Yes", "No", $files, "/mail/", false,
$ignoreline) ;
$snr -> doSearch() ;
?>

Rate this topic:
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4 out of 5)
Loading ... Loading ...
Popularity: 804 views
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Comments on “PHP: Replace string in TXT file”

  • azimyasin
    27 February, 2008, 22:31

    $filearray = file(”filename.txt”);

    Is perhaps easier.

  • 26 March, 2008, 0:16

    thats for sure, man

Leave a Comment