Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

how can i get the SRC value inside IMG tag?

Last post 07-08-2008, 11:18 AM by tohjg. 2 replies.
Sort Posts: Previous Next
  •  07-05-2008, 6:42 AM 43781

    how can i get the SRC value inside IMG tag?

    I got this bunch of strings from RSS and i want to extract SRC (source) value from IMG tag.

    <a title="test01" rel="lightbox[pics5]" href="http://blog.apostrophegallery.com/wp-content/uploads/2008/07/dsc_6620.jpg"><img class="attachment wp-att-7 alignleft" src="http://blog.apostrophegallery.com/wp-content/uploads/2008/07/dsc_6620.jpg" alt="test01" width="390" height="200" /></a><a title="test01" rel="lightbox[pics5]" href="http://blog.apostrophegallery.com/wp-content/uploads/2008/07/dsc_6620.jpg"><img class="attachment wp-att-7" src="http://blog.apostrophegallery.com/wp-content/uploads/2008/07/dsc_6620.jpg" alt="test01" width="390" height="200" /></a></p>
    <p>Test image</p>

    How can i do that? I'm using PHP regular expression.

    Thanks in advance. 

    -darien 

  •  07-07-2008, 7:26 PM 43847 in reply to 43781

    Re: how can i get the SRC value inside IMG tag?

    Try:

    <img\s.*?src=("[^"]*"|\S*)

    with the 'ignore case' option set if the 'img' and 'src' could be in uppercase. The value you want is in match group #1.

    This picked out the two instances in your test string. 

    Susan 

  •  07-08-2008, 11:18 AM 43888 in reply to 43847

    Re: how can i get the SRC value inside IMG tag?

    thanks for the help.

    I found my own solution to this and just share it to everyone.


    $imgSrcPattern = '/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'\s>]*)/i';

     

View as RSS news feed in XML