Re: [PHP] RegEx gurus help...
The code below does almost of the job. There is only one problem. If some path is absolute to the server /aaa/bbb/ the path get file://aaa// but I think no problems with apache. HTH Andrey Hristov IcyGEN Corporation http://www.icygen.com BALANCED SOLUTIONS pre ?php $the_html = 'I need to replace all relative links in an html doc with absolute links on the fly weather it be an image link, img src=\'/_imgs/imgs_nav/transPix.gif\' width=\'10\' height=\'13\' img src=\'../_imgs/imgs_nav/transPix.gif\' width=\'10\' height=\'13\' a URL, a href=/dealers/index.asp a link to an external JS file script language=\'JavaScript\' src=\'/_js/scripts.js\' type=\'text/javascript\'/script or external css file. link rel=stylesheet href=../_css/style.css type=text/css'; echo htmlspecialchars($the_html); $ABSOLUTE_HREF = 'http://someserver.com/somedir/somedir2/'; $count = preg_match_all('~(src=|href=)(|\')(?!href://)(.*?)(\2)~',$the_html,$matches); var_dump($matches); $the_html = preg_replace('~(src=|href=)(|\')(?!href://)(.*?)(\2)~','\1\2'.$ABSOLUTE_HREF.'\3\4',$the_html); echo htmlspecialchars($the_html); ? - Original Message - From: Brian V Bonini [EMAIL PROTECTED] To: PHP Lists [EMAIL PROTECTED] Sent: Monday, December 10, 2001 4:21 PM Subject: [PHP] RegEx gurus help... I need to replace all relative links in an html doc with absolute links on the fly weather it be an image link, img src='/_imgs/imgs_nav/transPix.gif' width='10' height='13' img src='../_imgs/imgs_nav/transPix.gif' width='10' height='13' a URL, a href=/dealers/index.asp a link to an external JS file script language='JavaScript' src='/_js/scripts.js' type='text/javascript'/script or external css file. link rel=stylesheet href=../_css/style.css type=text/css Anyone done this before and have a prefab regex laying around they want to share? -Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] RegEx gurus help...
I need to replace all relative links in an html doc with absolute links on the fly weather it be an image link, img src='/_imgs/imgs_nav/transPix.gif' width='10' height='13' img src='../_imgs/imgs_nav/transPix.gif' width='10' height='13' a URL, a href=/dealers/index.asp a link to an external JS file script language='JavaScript' src='/_js/scripts.js' type='text/javascript'/script or external css file. link rel=stylesheet href=../_css/style.css type=text/css Anyone done this before and have a prefab regex laying around they want to share? -Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] RegEx gurus help...
from the way you describe, i can't help but think that it'd be one hell of a regex.if all you're doing is stripping out .. i'd load up your fav editor and do a search and replace where you can approve each changeor, just change them all and fix what's broken.it'll be much quicker than trying to write a regex for all of that -Original Message- From: Brian V Bonini [mailto:[EMAIL PROTECTED]] Sent: Monday, December 10, 2001 9:22 AM To: PHP Lists Subject: [PHP] RegEx gurus help... I need to replace all relative links in an html doc with absolute links on the fly weather it be an image link, img src='/_imgs/imgs_nav/transPix.gif' width='10' height='13' img src='../_imgs/imgs_nav/transPix.gif' width='10' height='13' a URL, a href=/dealers/index.asp a link to an external JS file script language='JavaScript' src='/_js/scripts.js' type='text/javascript'/script or external css file. link rel=stylesheet href=../_css/style.css type=text/css Anyone done this before and have a prefab regex laying around they want to share? -Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] RegEx gurus help...
Hey thanks! That was a good starting point... -Brian -Original Message- From: Andrey Hristov [mailto:[EMAIL PROTECTED]] Sent: Monday, December 10, 2001 9:35 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [PHP] RegEx gurus help... The code below does almost of the job. There is only one problem. If some path is absolute to the server /aaa/bbb/ the path get file://aaa// but I think no problems with apache. HTH Andrey Hristov IcyGEN Corporation http://www.icygen.com BALANCED SOLUTIONS pre ?php $the_html = 'I need to replace all relative links in an html doc with absolute links on the fly weather it be an image link, img src=\'/_imgs/imgs_nav/transPix.gif\' width=\'10\' height=\'13\' img src=\'../_imgs/imgs_nav/transPix.gif\' width=\'10\' height=\'13\' a URL, a href=/dealers/index.asp a link to an external JS file script language=\'JavaScript\' src=\'/_js/scripts.js\' type=\'text/javascript\'/script or external css file. link rel=stylesheet href=../_css/style.css type=text/css'; echo htmlspecialchars($the_html); $ABSOLUTE_HREF = 'http://someserver.com/somedir/somedir2/'; $count = preg_match_all('~(src=|href=)(|\')(?!href://)(.*?)(\2)~',$the_htm l,$matches); var_dump($matches); $the_html = preg_replace('~(src=|href=)(|\')(?!href://)(.*?)(\2)~','\1\2'.$AB SOLUTE_HREF.'\3\4',$the_html); echo htmlspecialchars($the_html); ? - Original Message - From: Brian V Bonini [EMAIL PROTECTED] To: PHP Lists [EMAIL PROTECTED] Sent: Monday, December 10, 2001 4:21 PM Subject: [PHP] RegEx gurus help... I need to replace all relative links in an html doc with absolute links on the fly weather it be an image link, img src='/_imgs/imgs_nav/transPix.gif' width='10' height='13' img src='../_imgs/imgs_nav/transPix.gif' width='10' height='13' a URL, a href=/dealers/index.asp a link to an external JS file script language='JavaScript' src='/_js/scripts.js' type='text/javascript'/script or external css file. link rel=stylesheet href=../_css/style.css type=text/css Anyone done this before and have a prefab regex laying around they want to share? -Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] RegEx gurus help...
I need to replace all relative links in an html doc with absolute links on the fly weather it be an image link, img src='/_imgs/imgs_nav/transPix.gif' width='10' height='13' img src='../_imgs/imgs_nav/transPix.gif' width='10' height='13' a URL, a href=/dealers/index.asp a link to an external JS file script language='JavaScript' src='/_js/scripts.js' type='text/javascript'/script or external css file. link rel=stylesheet href=../_css/style.css type=text/css Anyone done this before and have a prefab regex laying around they want to share? -Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]