branmh Posted January 15, 2017 Share Posted January 15, 2017 (edited) 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 January 15, 2017 by requinix Quote Link to comment Share on other sites More sharing options...
requinix Posted January 15, 2017 Share Posted January 15, 2017 Step 1: stop using regular expressions to parse XML. There are better alternatives. There is no step 2. The CDATA stuff won't be a problem because libraries that can parse XML know how to handle it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.