hi
need little help displaying xml data from two website

need to display data like this
1-website a
2-website b
3-website a
4-website b

i am using this code

can any one tell me how i can display two xml data from different websites
i am using this
what i have to do that this can display date in same foreach loop

function getFeedAll() {

$content = file_get_contents("weblink");

$x = new SimpleXmlElement($content);

echo "<ul>";

foreach($x->channel->item as $entry) {
echo "
<li>
<a href='$entry->link' title='$entry->title' target='_new'> " . $entry->title . "</a>
</li>";
}

echo "</ul>";
}

Here's an example:

------------
file: a.xml
------------

<xml>
	<channel>
		<item>
			<title>a title 1</title>
			<link>a_link_1</link>
		</item>
		<item>
			<title>a title 2</title>
			<link>a_link_2</link>
		</item>
		<item>
			<title>a title 3</title>
			<link>a_link_3</link>
		</item>
	</channel>
</xml>


------------
file: b.xml
------------

<xml>
	<channel>
		<item>
			<title>b title 1</title>
			<link>b_link_1</link>
		</item>
		<item>
			<title>b title 2</title>
			<link>b_link_2</link>
		</item>
		<item>
			<title>b title 3</title>
			<link>b_link_3</link>
		</item>
		<item>
			<title>b title 4</title>
			<link>b_link_4</link>
		</item>
	</channel>
</xml>


---------------
file: read.php
---------------

<?php
$a = file_get_contents('a.xml');
$b = file_get_contents('b.xml');
$xa = new SimpleXmlElement($a);
$xb = new SimpleXmlElement($b);	

$na = $xa->channel->item->count();
$nb = $xb->channel->item->count();
$c = ($na == $nb) ? $na : max($na,$nb);	# how many loops? in this example 4 because b.xml has 4 items

if($c != 0)
{
	echo '
	<ul>
	';
	for($i = 0; $i < $c; $i++)
	{
		if($xa->channel->item[$i] == true)
		{
			echo '
			<li><a href="'.$xa->channel->item[$i]->link.'">'.$xa->channel->item[$i]->title.'</a></li>
			';
		}
		
		if($xb->channel->item[$i] == true)
		{
			echo '
			<li><a href="'.$xb->channel->item[$i]->link.'">'.$xb->channel->item[$i]->title.'</a></li>
			';
		}
	}
	echo '
	</ul>
	';
}
?>

Just change $c to (for example) $c = 2; if you want to control how many links your application is going to display. Bye :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.