Jump to content

Get substring after specific char position up to occurence of another char


mattspriggs28

Recommended Posts

Hi,

 

I have an html page with multiple image tags inside it.

 

I'm wanting to get the full URL of a specific image within that file.

 

The specific image I'm looking for must start with 'http://www.mysite.com/images/' in the src part of the tag to make sure I'm getting the correct image.

 

To find the occurence, I'm using strpos() to find the character position of the string match.

 

What I then need to do is complete the rest of the URL to get the image name and then output this.

 

So basically I need to get the string that comes after 'http://www.mysite.com/images/' and end when the speech mark occurs to close the src part of the image tag.

 

This will then give me the full URL of my image.

 

How do I do this? Or is there a better way to do this?

 

Thanks.

presuming you have captured the following

$string1 = '<img src="http://www.mysite.com/products/images/123.jpg" alt="">';

simply

$array_1 = explode('"', $string1); /* that is a double quote surrounded by single quotes */
$image_url = $array_1[1];

 

Not quite, I have the strpos of the string 'http://www.mysite.com/images/' which may be 42, so I want to start from strpos() + length (which in the example URL I guess would be 71) of my substring up to when the next double quote appears to get the remainder of the image URL. So basically I want to get from strpos 71 up to (but not including) the next occurence of a double quote to give me the remainder of the URL.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.