Jump to content

Recommended Posts

Hello, I have some code that pulls in an RSS feed. The issue is that the 'description' contains CDATA with text, link and images code. I just need to pull out 'parse' the image url and have it avalible in a string variable. I'm not sure what else to say, so please ask if you need more information. Thanks for your time and help!

Link to comment
https://forums.phpfreaks.com/topic/132315-solved-parsing-a-string-for-url/
Share on other sites

Here is the item code:

 

<item>
  <title>Example URL</title> 
  <link>http://www.exampleurl.com/</link> 
  <guid isPermaLink="false">guid_2008-11-11-1876</guid> 
  <description>
    <![CDATA[ Some sample content is included here.<br><a border="0" href="http://www.exampleurl.com/" target="_blank"><img src="http://www.exampleurl.com/rss_image.jpg"/></a> ]]> 
  </description>
  <pubDate>Tue, 11 Nov 2008 00:00:00 -0800</pubDate> 
</item>

 

I’m not familiar with SimpleXML. Will that break out the CDATA? Thank you very much for your help!

Let's say you have this string:

 

    <![CDATA[ Some sample content is included here.<br><a border="0" href="http://www.exampleurl.com/" target="_blank"><img src="http://www.exampleurl.com/rss_image.jpg"/></a> ]]>

 

If you have that string you can easily get the img url by doing the following:

 

<?php
$string = ' <![CDATA[ Some sample content is included here.<br><a border="0" href="http://www.exampleurl.com/" target="_blank"><img src="http://www.exampleurl.com/rss_image.jpg"/></a> ]]>';

$parsed = explode("src=\"", $string);
$parsed = explode("\"/>", $parsed[1]);
$imageUrl = $parsed[0];
echo $imageUrl;
?>

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.