I'm capturing data from an external url using php and throwing it back to my page via ajax to load images. My problem is the external url have some images that are relative("images/example.jpg") so I have to prepend their base domain("http://www.example.com) so I can load it in my page. Problem is some of the images includes a base domain url yet some are in their relative form. Im guessing maybe use regex in my javascript to the determines the string if it have a base("http://example.domain.com") or just a relative("images/") to it. How can I achieve that through regex?
views:
197answers:
3
A:
Parse the URL from within the PHP script using parse_url. If the associative array does not contain the keys host
or scheme
, you can rewrite the URL to include them.
Alan Haggai Alavi
2009-05-25 03:52:46
I have editted my description to a clearer one. I can't do the parsing of a url through php because im getting a lot of html tags and passing them back to my page via jquery then load it from there.
cybervaldez
2009-05-26 03:09:47
A:
You won't be able to distinguish between a relative url like "images/blank.gif" and a relative url that has "www.theirdomain.com/images/blank.gif". Who is to say that "www.theirdomain.com" isn't a directory?
If the url does not start with http://, https:// or // it is relative to the url of the page where you scraped them from.
Mario Menger
2009-05-25 10:12:35
if an image has src="www.theirdomain.com/images/blank.gif" then it IS a directory.
nickf
2009-05-29 01:29:23