Reputation: 990
I got some XML Atom files on local.
On all of those files, there are some <author>...</author>
balise that I want to catch in a PHP string variable.
So I did that :
function parseAtomByBalise($xml,$balise) {
$arrayStr=array();
preg_match('#<'.$balise.'>(.*)</'.$balise.'>#',$xml,$arrayStr);
return $arrayStr;
}
$fxml=fopen($xml,'r');
$strXML=fgets($fxml);
echo '<p>author: <textarea>';
$authors=parseAtomByBalise($strXML,'author');
foreach($authors as $author) {
if($author!=$strXML)
echo $author.'\n';
}
echo '</textarea></p>';
}
Files are opening, and strXML is the good string.
I got some stranges behaviours of preg_match, that makes me think that this is not the good function... I got more balises than only the balises insides <author></author>
How should I do ?
Upvotes: 0
Views: 132
Reputation: 53603
Regex
is not good for parsing XML(just an example, not the absolute proof, but...) PHP
built in tools like simple XMLUpvotes: 3