mattspriggs28 Posted October 14, 2010 Share Posted October 14, 2010 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 https://forums.phpfreaks.com/topic/215869-get-substring-after-specific-char-position-up-to-occurence-of-another-char/ Share on other sites More sharing options...
litebearer Posted October 14, 2010 Share Posted October 14, 2010 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]; Link to comment https://forums.phpfreaks.com/topic/215869-get-substring-after-specific-char-position-up-to-occurence-of-another-char/#findComment-1122169 Share on other sites More sharing options...
mattspriggs28 Posted October 14, 2010 Author Share Posted October 14, 2010 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 https://forums.phpfreaks.com/topic/215869-get-substring-after-specific-char-position-up-to-occurence-of-another-char/#findComment-1122178 Share on other sites More sharing options...
AbraCadaver Posted October 14, 2010 Share Posted October 14, 2010 preg_match('#"http://www.mysite.com/images/([^"]+)"#', $string, $matches); echo $matches[1]; Link to comment https://forums.phpfreaks.com/topic/215869-get-substring-after-specific-char-position-up-to-occurence-of-another-char/#findComment-1122207 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.