Hi,

I am trying to load an Rss link and add the data into an array. Here is what I am trying:

<?php
 
$doc = new DOMDocument();
$doc2 = new DOMDocument();
$bbcLink='http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/world/rss.xml';
 $cnnLink='http://rss.cnn.com/rss/edition.rss';
$reutersLink='';
    $doc->load($bbcLink);
 
 $arrFeeds = array();
foreach ($doc2->getElementsByTagName('item') as $node) {
		$itemRSS = array ( 
		   '<p class="style1">' => $node->getElementsByTagName('title')->item(0)->nodeValue,
			'</p>desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
			'link'=>$node->getElementsByTagName('link')->item(0)->nodeValue,
			'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
			);
		array_push($arrFeeds, $itemRSS);
	}
        
          function displayArrayContentFunction($arrayname,$tab="&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp",$indent=0) {
 $curtab ="";
 $returnvalues = "";
 while(list($key, $value) = each($arrayname)) {
     
  for($i=0; $i<$indent; $i++) {
   $curtab .= $tab;
   
   }
  if (is_array($value)) {
           
   $returnvalues .= "<br /><table width='1009' border='1'><tr><td width='926'><br />\n";
   $returnvalues .= displayArrayContentFunction($value,$tab,$indent+1)."</td><td width='67'>&nbsp;</td></tr></table><br />\n";
   }
  else $returnvalues .= "$curtab$key => $value<br />\n";
  $curtab = NULL;
  }
 return $returnvalues;
}

echo displayArrayContentFunction($arrFeeds);

Now, I get an error Cannot clone object of class DOMDocument due to 'zend.ze1_compatibility_mode'.
I did change the value of zend.zel_compatibility=off both in php.ini and .htaccess file but still no luck. Please see if you can help, I really having a hard time with this.

PS. it does work on my localhost but not on the webserver when uploaded.

Many thanks in advance

?>

Dani AI

Generated

As noticed, the setting name is zend.ze1_compatibility_mode (ze-one, not “zel”). That compatibility mode changes PHP object semantics (objects act like PHP4-style value copies), and that change forces internal objects (DOMDocument / DOMText / PDO, etc.) to be copied/cloned — which internal classes do not support, producing the fatal “Cannot clone object … due to 'zend.ze1_compatibility_mode'” error. (php.net)
php.ini directives (php.net) (bug #45879).

Fix checklist (in order of least to most intrusive): confirm the directive, then switch it off.

  • Check which php.ini is active and whether the directive is on by using phpinfo() (look for “Loaded Configuration File” and the directive value) or ini_get('zend.ze1_compatibility_mode'). (php.net)
  • If access to php.ini is available, edit the correct file and set zend.ze1_compatibility_mode = Off (or 0) and restart the webserver. If php.ini cannot be edited, a quick test is:
    ini_set('zend.ze1_compatibility_mode', 0);

    but note ini_set() only works for options that PHP allows to be changed at runtime; it can fail for some directives/SAPIs. (php.net)

If changing PHP settings is not possible on that host, a safe code workaround is to avoid paths that trigger cloning of DOM nodes (foreach or copying node objects). Iterate by index and call item($i) inline instead, which was reported to avoid the clone error. Example pattern:

$items = $doc->getElementsByTagName('item');
for ($i = 0; $i < $items->length; $i++) {
    $node = $items->item($i);
    echo $node->getElementsByTagName('title')->item(0)->nodeValue;
}

This approach is documented in bug reports as a working workaround. (bugs.php.net)

Note: zend.ze1_compatibility_mode was deprecated/removed in PHP 5.3.0 (so upgrading PHP removes the setting entirely). If on shared hosting, ask support to turn the mode off or to move to a newer PHP version. Also double-check that the DOMDocument being iterated is the one actually loaded (the original snippet created a second DOMDocument variable), since iterating an unloaded document will silently produce no items. (php.net)

You do realize that the error says ze1 as in z - e - one, and yours says zel as in z - e - L

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.