nickjonnes Posted July 31, 2011 Share Posted July 31, 2011 hey all, now i have tried for hours to try and figure this out and it seems so simple and now i am getting really frustrated with it. i want to take out the img source(line 7 and embed the image in my site.). the xml looks like this 1.<channel> 2. <item> 3. <title>blah</title> 4. <link>www.example.com</link> 5. <description> 6. <![CDATA[<p>blah blah blah blah blah</p><a href=http://link.com><img 7. src= http://www.linktoimage.com/link.jpg/></a> 8. </description> 9.</item> 10.</channel> Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/ Share on other sites More sharing options...
gizmola Posted July 31, 2011 Share Posted July 31, 2011 What do you have so far? That example doesn't even have a valid link in there: .... What is that? Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1249953 Share on other sites More sharing options...
AyKay47 Posted August 1, 2011 Share Posted August 1, 2011 Gizmo, I think that the OP was trying to distinguish that that is the start of line 7. if you look to the left the numbers go from 6. to 8... just a guess though.. you will want something like this.. $pattern = '~src=\s*http://www\.[a-zA-Z0-9_-]+\.[a-zA-Z]{2,4}/[a-zA-Z0-9_-]+\.[a-zA-Z]{3,4}~'; $subject = '<![CDATA[<p>blah blah blah blah blah</p><a href=http://link.com><img 7.src= http://www.linktoimage.com/link.jpg/></a>'; preg_match($pattern,$subject,$matches); print $matches[0]; will contain your img source Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1250016 Share on other sites More sharing options...
nickjonnes Posted August 3, 2011 Author Share Posted August 3, 2011 i dont understand how i can make it get the source from a url like so. http://example.com (which contains the image) Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1251129 Share on other sites More sharing options...
AyKay47 Posted August 3, 2011 Share Posted August 3, 2011 from the actual URL you wont be alble to display an image using the url as the source.. however if you know that actual path to the image..you can use CURL Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1251174 Share on other sites More sharing options...
gizmola Posted August 3, 2011 Share Posted August 3, 2011 from the actual URL you wont be alble to display an image using the url as the source.. however if you know that actual path to the image..you can use CURL Huh? If you have the url to an image, you can access the image. I'm not sure I understand what you are trying to say here AyKay... Of course I'm not clear on what the OP wants. I thought he had an xml feed of some type and just wants to get the img url that's contained in the CDATA. Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1251389 Share on other sites More sharing options...
xyph Posted August 3, 2011 Share Posted August 3, 2011 I think I've answered this already here http://www.phpfreaks.com/forums/index.php?topic=340341.msg1604441#msg1604441 Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1251406 Share on other sites More sharing options...
Jeffro Posted August 3, 2011 Share Posted August 3, 2011 I struggled with this a few months ago myself... Here's what worked for me. It looks malformed but it does the job... <description> <IMG width="50" height="140" border="0" src="<?=$site_url?>/pics/images/pic/<?=$row['image']; ?>" alt="rss image"/></description> Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1251438 Share on other sites More sharing options...
AyKay47 Posted August 3, 2011 Share Posted August 3, 2011 from the actual URL you wont be alble to display an image using the url as the source.. however if you know that actual path to the image..you can use CURL Huh? If you have the url to an image, you can access the image. I'm not sure I understand what you are trying to say here AyKay... Of course I'm not clear on what the OP wants. I thought he had an xml feed of some type and just wants to get the img url that's contained in the CDATA. honestly the OP has confused me.. Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1251517 Share on other sites More sharing options...
nickjonnes Posted August 7, 2011 Author Share Posted August 7, 2011 yes i have an xml feed here is the link if you would like: http://feeds.nationalgeographic.com/ng/photography/photo-of-the-day.atom i want to get the picture of the day and post it on my website. i am sorry for any confusion. Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1253625 Share on other sites More sharing options...
gizmola Posted August 7, 2011 Share Posted August 7, 2011 You have to be clear about what you mean by "post it on my website". Are you trying to download the image and store it somewhere on your server, so that you can display it, or do you simply mean you want the url to the image, so that you can store that and later you will use in in an img tag? Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1253892 Share on other sites More sharing options...
nickjonnes Posted August 8, 2011 Author Share Posted August 8, 2011 i will be embedding it. Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1254052 Share on other sites More sharing options...
salathe Posted August 8, 2011 Share Posted August 8, 2011 Don't use regex. PHP has built-in XML parsing tools available to make the job much easier. One such tool is SimpleXML and the example below shows how to loop over each <item> and display the associated image. Have a read through the SimpleXML Examples page too. $feed = simplexml_load_file('http://feeds.nationalgeographic.com/ng/photography/photo-of-the-day.atom'); foreach ($feed->channel->item as $item) { printf('<img src="%s"><br>', $item->enclosure['url']); } (And here's it working online.) Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1254163 Share on other sites More sharing options...
nickjonnes Posted August 8, 2011 Author Share Posted August 8, 2011 holy crap i love you! i have had this an another thing that i have spent ages on - simply because i am not php coder - and you have solved it thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1254240 Share on other sites More sharing options...
AyKay47 Posted August 8, 2011 Share Posted August 8, 2011 holy crap i love you! i have had this an another thing that i have spent ages on - simply because i am not php coder - and you have solved it thank you so much no homo...? Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1254242 Share on other sites More sharing options...
salathe Posted August 9, 2011 Share Posted August 9, 2011 holy crap i love you! Happy to help in guiding you in the right direction. no homo...? What? Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1254780 Share on other sites More sharing options...
nickjonnes Posted August 11, 2011 Author Share Posted August 11, 2011 yes no homo ;)lol Quote Link to comment https://forums.phpfreaks.com/topic/243367-getting-a-img-source/#findComment-1255632 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.