rocklee Posted April 7, 2010 Share Posted April 7, 2010 Hi, I'm currently using str_replace to parse through my content to replace IMG tags with HTML codes <IMG src....>. An example code is as followed : $content = str_replace("[img]http://", "<img WIDTH=480 class='image_center' src='", $content); $content = str_replace("[/img]", "'>", $content); $content is a bunch of text that contains tags, it may have a number of IMG tags, which is why I use str_replace to quickly browse through it and replace them for HTML output. This works fine but I want to get the URL address of my images and use them as a link as well. I can't do it with this set up because it only replaces the tags, i want to get the url between the tags. Any ideas? Link to comment https://forums.phpfreaks.com/topic/197821-extracting-details-between-tags-from-content/ Share on other sites More sharing options...
sspoke Posted April 7, 2010 Share Posted April 7, 2010 [code=php:0] <?php $html= "<img class=\"...\" src=\"s...\""; $html .= "alt='...' title='...' />"; $pattern = '/<img[^>]+src[\\s=\'"]'; $pattern .= '+([^"\'>\\s]+)/is'; if(preg_match($pattern, $html, $match)) { echo "image link: " . $match[1]; } ?> Link to comment https://forums.phpfreaks.com/topic/197821-extracting-details-between-tags-from-content/#findComment-1038141 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.