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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.