Forum Moderators: coopster
if (eregi('<actor>(.*)</actor>',$record,$actor)) {
print ('<b>Starring:</b> '.$actor[1]); }
.....from the following piece of XML......
<ItemAttributes>
<Actor>Tobey Maguire</Actor>
<Actor>Kirsten Dunst</Actor>
<Actor>Alfred Molina</Actor>
</ItemAttributes>
Problem is the result looks like this:-
Starring: Tobey MaguireKirsten DunstAlfred Molina
Note the lack of spaces. How can I add a space in between each name?
Thanks, Pete
<b>Starring:</b> Tobey Maguire</Actor>If you want just the names peeled out, you'll have to change your regular expression. I use preg_match_all [php.net] rather than ereg, it's faster. The Uis switches tell it to be Ungreedy, ignore case, and if the $record is on more than one line, take the newlines into consideration:
<Actor>Kirsten Dunst</Actor>
<Actor>Alfred Molina
if (preg_match_all('/<actor>(.*)<\/actor>/Uis', $record, $actor)) {
print ('<b>Starring:</b> '.implode(' ', $actor[1]));
}
implode() [php.net] is a slick way to put the spaces in ;)
Resource:
PCRE [php.net]