Jump to content

XML and issues with CDATA


branmh

Recommended Posts

Having an issue within the <description> node, it contains a header line and then followed by <![CDATA[ story paragraph [/size]]]>. 

How to create another variable for everything inside the CDATA? and/or how to remove that entirely? Thanks in advance.  

//this remove all a href from rawdata
$rawdata = preg_replace('@<a href=[^>]+>(.*)</a>@', '', $rawdata);
$rawdata = preg_replace('/<pre>/', '', $rawdata);
$rawdata = preg_replace('/<\/pre>/', '', $rawdata);
$rss_update = preg_match_all("/<pubDate>(.*)<\/pubDate>/", $rawdata, $rss_update);
 
$types = array(
'link',
'description',
'title',
'pubDate',
'author');
 
 
$valid = array();
$link = $description = $title = $pubDate = $author = array();
 
$rawdata = preg_replace('/<item>/', "<item>\s", $rawdata);
if (preg_match_all('/<item>(.+?)<\/item>/s', $rawdata, $r))
{
$rr = count($r[0]);
for ($i = 0; $i < $rr; $i++)
{
if (preg_match_all('/<(.+?)>(.+?)<\//s', $r[1][$i], $y))
{
$yy = count($y[0]);
for ($x = 0; $x < $yy; $x++)
{
if (in_array($y[1][$x], $types))
{
array_push(${$y[1][$x]}, $y[2][$x]);
 
} 
}
}   
}
 
}
if ($this->debug)
echo "rss total  $i\n";
$this->smarty->assign('rss_update', $rss_update);
$this->smarty->assign('rss_link', $link);
$this->smarty->assign('rss_description', $description);
$this->smarty->assign('rss_title', $title);
$this->smarty->assign('rss_pubdate', $pubDate);
$this->smarty->assign('rss_author', $author);
$this->smarty->assign('rss_story', $story);
$this->smarty->assign('rss_total', $i);
Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.