<?php
function ez_xml_extract($string, $tag) {
// FIND THE OPENING TAGS IF ANY EXIST
$tag_array = explode('<' . $tag . '>', $string);
if (empty($tag_array)) {
return FALSE;
}
// DISCARD THE UNUSED STUFF (PROBABLY <?XML TAG)
unset($tag_array[0]);
// ITERATE OVER THE RESULTING CONTENTS, COLLECTING THE OUTPUT
foreach ($tag_array as $tag_data) {
$my_tag = explode('</' . $tag . '>', $tag_data);
$output[] = $my_tag[0];
}
return $output;
} // ! EZ_XML_EXTRACT
$str="
<root>
<users>
<user>Mike</user>
<user>Richard</user>
<user>Ana</user>
</users>
</root>";
var_dump(ez_xml_extract($str, 'user'));
$non_str="
<root>
<users>
<nouser>Mike</nouser>
<nouser>Richard</nouser>
<nouser>Ana</nouser>
</users>
</root>";
var_dump(ez_xml_extract($non_str, 'user'));
?>
I really do not need links: I have thousands of them: just a little snippet of code to do this simple XML parsing