I have a script which parses xml feeds, the url's to the feeds that are being parsed are in a table on my database.

Below is the query for storing the url's in an array

$getUrls = "SELECT * FROM sscape_blogroll";
$result = mysql_query($getUrls);
$urls = array();
while($row = mysql_fetch_array($result)){
	$urls[$row[0]] = $row[2];
}

This works fine providing there are only 2 url's in the table, if there are more I get the error message 'The string could not be parsed as XML'

These are the various functions that grab the RSS, aggregate the blogs, and adds the feeds

public function addFeeds( array $feeds )
	{
		$this->urls = array_merge( $this->urls, array_values($feeds) );
	}
	public function grabRss()
	{
		foreach ( $this->urls as $feed )
		{
			$data = @new SimpleXMLElement( $feed, 0, true );
			if ( !$data )
				throw new Exception( 'Could not load: ' . $feed );
			foreach ( $data->channel->item as $item )
			{
				$this->data[] = $item;
			}
		}
	}
	public function amalgamate()
	{
		//shuffle( $this->data );
		$temp = array();
		foreach ( $this->data as $item )
		{
			if ( !in_array($item->link, $this->links($temp)) )
			{
				$temp[] = $item;
			}
		}
		$this->data = $temp;
		shuffle( $this->data );
	}

If anyone can help me out that would be much appreciated

Hi lit108,
your code doesn't show where you get the XML string. Are you calling
addFeeds() with $urls from the first snippet?

If you don't modify or create the XML then the XML stored in the database must already be bad. It's probably not that 'more than 2 urls' trigger the bug, but the particular XML string that you added is buggy.

It could even be that the XML you store into the db is ok but the db field name is too short (e.g. VARCHAR(255) instead of TEXT) and it gets truncated.

You should try printing $feed that you pass to SimpleXMLElement() and post here the string that triggers the error.

btw: Array keys from $urls are not used so you can ignore $row[0]. Also, for clarity, use $row and not $row[number].

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.