LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   use php script to parse a file. (https://www.linuxquestions.org/questions/linux-software-2/use-php-script-to-parse-a-file-202055/)

blackzone 07-07-2004 02:47 AM

use php script to parse a file.
 
if I have a file such as >>

"
FirstLine
SecondLINE DONTWANT
Third WANT 1.2.3
FORTH DONTWANT
"

what is the best way to use php script to capture the number after WANT

ie(I want to capture the string "1.2.3")

keefaz 07-07-2004 04:43 AM

PHP Code:

<?php
$lines 
file"your_file.txt" );

for( 
$i 0$i sizeof($lines); $i++ )
{
    if (
preg_match("/\\d\\.\\d\\.\\d/"$lines[$i]) )
    {
        
$str ereg_replace"^(.*) """$lines[$i] );
        echo 
"$str\n";
    }
}
?>



All times are GMT -5. The time now is 12:36 PM.