Re: Changing URLs from Relative to Absolute

From: Date: Mon, 30 Jul 2007 12:44:04 +0000
Subject: Re: Changing URLs from Relative to Absolute
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-259807@lists.php.net to get a copy of this message
In general, you must have patterns and code that deal with most common errors. As to your example, your regex pattern must not be good. Is your complete string simply: <img a="A photo" src="images/1.jpg"> ? If so, then "%src\x20*=\x20*\"*([\w/]+\x2Ejpg)%i" should do it for you. \x20*, may have 0 or more spaces; \x2E = period; "()" will capture the file name; "i" can handle upper or lower case. Incidentally, be careful that you have good security checking on the "pasted" in html stuff. Tom Chubb wrote:
Dear list, I was recently trying to write a script where a user copy and pastes their HTML code to display something on a listings site and tried to find a way to change the URL of an image from relative to absolute. For example <img src="images/1.jpg"> becomes <img = src=" http://domain.com/images/1.jpg">. That is easy enough and I created a regexp, but I found that some people call the img tag differently such as: <img a="A photo" src="images/1.jpg"> Does anyone have experience of this? How can I create a regexp that will find it in every case? Thanks in advance. Tom


« previous php.general (#259807) next »