This is the code I am working with:
<?php
$rss = new DOMDocument();
$rss->load('http://hugeriver.wordpress.com/feed/');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('encoded')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = count($feed);
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));
echo '<h2><a name="test">'.$title.'</a><span class="line"></span></h2>';
echo '<small><em>Posted on '.$date.'</em></small></p>';
echo '<p>'.$description.'</p>';
}
?>
I am stuck specifically with this line. I am trying to make it so the title is both the name of the ancor and the link (so when clicked it scrolls to the top). This is what I tried that doesn't work. Can anyone please show me what is wrong with my syntax?
echo '<h2><a name="'.$title'" href="#'.$title'">'.$title.'</a><span class="line"></span></h2>';
echo '<h2><a name="'.$title.'" href="#'.$title.'">'.$title.'</a><span class="line"></span></h2>';
You are missing dots after $title
Also, your links link to themself. You need to define a seperate anchor and then link to it.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments