Travis Hydzik
asked on
PHP regex help preg_replace
experts,
I need some help with some regex and the php function preg_replace.
for some reason this is not working;
this is my input
in summary I am converting relative links to absolute.
thanks
I need some help with some regex and the php function preg_replace.
for some reason this is not working;
$ret = preg_replace('/((?:href|src) *= *[\'"])(?!(http|ftp))/i', 'this is a test', $ret);
this is my input
<marker icon="Marker.png" name="gcc1b3-rockin-around-the-salt-photo-five.jpg" width="2048" height="1536" thmname="gcc1b3-rockin-around-the-salt-photo-five-th.jpg" thmwidth="160" thmheight="120" date="16/03/2008 10:59:36 AM" datum="WGS 1984" alt="164.4553" altunits="feet" title="GCC1B3 Rockin' Around the Salt" html="<div id="infotitle">GCC1B3 Rockin' Around the Salt</div><div id="infoimg"><a href='gcc1b3-rockin-around-the-salt-photo-five.jpg' title='Click for a full size view' target='_blank'><img src='gcc1b3-rockin-around-the-salt-photo-five-th.jpg' width='160' border='0' height='120' /></a></div>" lat="-20.67069" lng="116.73424"/>
in summary I am converting relative links to absolute.
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what about if double quotes are used instead of single?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
original regex was correct.
ASKER
sorry, missing one set of brackets
$ret = preg_replace('/((?:href|src) *= *(?:'|")(?!(http|ftp)))/i', "$1".$xml_path, $ret);
ASKER
I am thinking it would be something similar to
$ret = preg_replace('/((?:href|sr
where $url is the absolute url i.e. http://mysite.com/ in the example.
if they are already absolute urls then it should be skipped.