Your original code posted
worked just fine for me 🙂
But I do not have your actual XML source.
I used a madeup text string to test it.
If your code does not work, it is not because of your preg_match
it is because XML data read from file is not what you think it is.
It might even be EMPTY!!!!
I have modified the preg_match pattern to the very most simplest I could get working.
This is it:
<?php
$xml = "
<player>gamer1</player>some<href> text <player>gamer2</player>some text <player>
gamer3</player>some text";
/*
$f = fopen( 'books.xml', 'r' );
while( $data = fread( $f, 4096 ) ) { $xml .= $data; }
fclose( $f );
*/
//preg_match_all( "/\<player\>(.*?)\<\/player\>/s", $xml, $players );
preg_match_all( "#<player>(.*?)</player>#s", $xml, $players );
foreach( $players[1] as $player )
{
echo $player.'<br />'; // displays: gamer1 gamer2 gamer3
}
?>