Re: removing text from a string

From: Date: Tue, 04 Nov 2008 14:33:31 +0000
Subject: Re: removing text from a string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-282855@lists.php.net to get a copy of this message
Adam Williams a écrit :
I have a file that looks like: 1. Some Text here 2. Another Line of Text 3. Yet another line of text 340. All the way to number 340 And I want to remove the Number, period, and blank space at the begining of each line. How can I accomplish this? Opening the file to modify it is easy, I'm just lost at how to remove the text.: <?php $filename = "results.txt"; $fp = fopen($filename, "r") or die ("Couldn't open $filename"); if ($fp) { while (!feof($fp))
       {
       $thedata = fgets($fp);
       //Do something to remove the "1. "
       //print the modified line and \n        }
fclose($fp); } ?>
<?php $filename = "results.txt"; $fp = fopen($filename, "r") or die ("Couldn't open $filename"); if ($fp) { while (!feof($fp))
       {
       $thedata = fgets($fp);
// search the ' ', return the content after ' ' (with the space) // trim remove the spaces at the start and the end of the line $newLine = trim(strstr($thedata,' '));
    }
fclose($fp); } ?>

« previous php.general (#282855) next »