Load with url variable

HI, I apologize for my question as i know that even category Beginners is too high for me.
I am trying to integrate feed from wordpress on html. Code works fine with url, but when i try to ad url variable the code always shows error. I tried two versions, but none works. ( the variables work)
So i suspect either load does not work the way i think or what is in bold is not correct.
I would be extremely grateful if someone opens my eyes.

$rss->load('<?php echo 'http://blog.wordpress.com/tag/'.$event['Event']['name'].'/'.feed/'. '?>');

version 2 in the code below

	$rss = new DOMDocument();
	$rss->load('http://blog.wordpress.com/tag/<?= $event['Event']['name'] ?>./feed/');
	$feed = array();
	foreach ($rss->getElementsByTagName('item') as $node) {
		$item = array ( 
			'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
			'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
			'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
		array_push($feed, $item);
	$limit = 1;
	for($x=0;$x<$limit;$x++) {
		$title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
		$link = $feed[$x]['link'];
		$description = $feed[$x]['desc'];
		$date = date('l F d, Y', strtotime($feed[$x]['date']));
		echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
		echo '<p>'.$description.'</p>';

You need to concatenate the variable. (period [.] is the concatenate operator in PHP)


For better security, you should also validate $event[‘Event’][‘name’] before hand.

Thank you. You made my day. I spent at least 3 hours trying to do it. Thanks a million.
One thing i do not understand, what do you mean by “For better security, you should also validate $event[‘Event’][‘name’] before hand.” ? You mean a need to do something else or that is just a clarification?

Seems there is no place on the code to add target="_blank"> so it can open as external page?

I don’t know where $event[‘Event’][‘name’] comes from so it is probably fine. I was just suggesting that you be sure it is safe in case it was directly entered by the user. From the title of your post, I was thinking of $_GET parameters, which users can modify. However, I don’t think that applies in this case.

Sponsor our Newsletter | Privacy Policy | Terms of Service