Hi there,

I am building a blog at the moment i have a amazing script that search a post for the images in it. So i can just setup a post template, call the images that are in the post and go. In this way i put the images unedited and unresized in the post and the template will make everything nice and smooth.:)

The thing is that the function works great, it produces a nice image with the image tags. Only the thing is:

I don't want the whole image wrapped up in a image tag,
i want only the src of it, i mean the url of the image.

I searched a lot but couldn't find a solution so thats why this posts excists.

Here is the function.

function getImage($num) {
global $more;
$more = 1;
$link = get_permalink();
$content = get_the_content();
$count = substr_count($content, '<img');
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, '<img', $start);
$post = substr($content, $imgBeg);
$imgEnd = strpos($post, '>');
$postOutput = substr($post, 0, $imgEnd+1);
$postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);;
$image[$i] = $postOutput;
if(stristr($image[$num],'<img')) { echo '<a href="'.$link.'">'.$image[$num]."</a>"; }
$more = 0;

I just call the images with

<?php getImageUrl('1'); ?>


<?php getImageUrl('2'); ?>


This will produce a in my case

<img class="a" title="htc-pure-1" src="http://www.site.com/wp-content/uploads/2010/03/htc-pure-1.jpg" alt="">

What i want is just


Onybody got a clue?

8 Years
Discussion Span
Last Post by Frankey

As well explained your post was I didn't exactly get the problem. From my understanding you want to use regex to extract links from html input. If that is correct then the following would be your solution.

$html_input='<img class="a" title="htc-pure-1" src="http://www.site.com/wp-content/uploads/2010/03/htc-pure-1.jpg" alt="">';



i will use yours instead for the better preformence! thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.