I have this little PHP code:
<?php
$r = file("id.txt");
$content = implode(" ",$r);
if (preg_match('#"name":[^"]*"([^"]*)"#', $content, $datos)) {
$mp = $datos[1];
} else {
$mp = 'error';
}
echo $mp;
?>
Which is responsible for opening and searching using preg_match() the content of
"name":" content "
with the help of regular expressions inside the "id.txt" file.
Content of the "id.txt":
"name":"jose";
"name":"juan";
"name":"carlos";
"name":"luis";
It contains more than 50 lines
"name":""
with different names.
All goes well. The detail is that it only gives me the first name and what I want is to get all the names and store them in a variable.
preg_match() returns only the first match.
To get all of them, you should use preg_match_all() .
Code:
Result:
demonstration:
https://3v4l.org/RVJi6