0
I have a text file with a name teste.txt
, in it I have the following code:
<ID>490901</ID>
<ID>28602</ID>
<ID>298174</ID>
<ID>1081022</ID>
I want to create a script to view only the first line:
<ID>490901</ID>
Php file:
<?php
$search = '<ID>';
$lines = file('teste.txt');
foreach($lines as $line)
{
if(strpos($line, $search) !== false)
echo $line;
}
?>
But mine script in php me of the following result:
490901 28602 298174 1081022
How can I get just the 490901
?
You can add a
break
after theecho
to stop the execution offoreach
after finding the first ID, but should have better ways to do this.– Woss