loops - PHP foreach with two 'as'? -
hi there trying combine 2 loops of foreach have problem.
the problem <a href='$link'>
same results must different.
here code using:
<?php $feed = file_get_contents('http://grabo.bg/rss/?city=&affid=16090'); $rss = simplexml_load_string($feed); $doc = new domdocument(); @$doc->loadhtml($feed); $tags = $doc->getelementsbytagname('link'); foreach ($tags $tag) { foreach($rss $r){ $title = $r->title; $content = $r->content; $link = $tag->getattribute('href'); echo "<a href='$link'>$title</a> <br> $content"; } } ?>
where mistake? why it's not working , how make work properly? in advance!
both loops going through different resources cross joining records in them.
this should work data need:
<?php $feed = file_get_contents('http://grabo.bg/rss/?city=&affid=16090'); $rss = simplexml_load_string($feed); foreach ($rss $key => $entry) { if ($key == "entry") { $title = (string) $entry->title; $content = (string) $entry->content; $link = (string) $entry->link["href"]; echo "<a href='$link'>$title</a><br />" . $content; } }
Comments
Post a Comment