Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Extract URL From A String

    Hi

    I've spent ALL morning trying to get this to work, hope someone on here can help me!

    Ok, I have a string retrieved from a database that contains some HTML-formatted text. What I want to do is search through this text for all images and extract the URL's from them. So if the string consisted of...

    Code:
    blah blha blah <img src="http://www.mysite.com/image.jpg" /> blah blah blah
    Then I want to have the value http://www.mysite.com/image.jpg in a variable. I see what I have to do...search for all occurences of words that start with src=" and end with .jpg" and get the value out of the middle, but just can't suss out the way to make it work! Please help!

    Thanks

    AB

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Would you rather search the directory for .jpg images and create
    a list of them, or search the HTML text? If you know the directory,
    you can find all .jpg files that it contains.

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I needed to search the string which was HTML formatted text.

    I managed it in the end...

    Code:
    $imageurl=explode('src=',$row[2]);
    $string=explode('"',$imageurl[1]);
    if ((substr($string[1], -4, 4) == ".jpg"))
    {
    	echo $string[1];
    }
    although i'm convinced there is a much cleaner approach to doing it...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •