Forum Moderators: coopster
[edited by: eelixduppy at 6:31 pm (utc) on Feb. 2, 2010]
[edit reason] exemplified [/edit]
$html = '<img src="/something.jpg">'; /*the html source you are sending*/
$urlbase = 'http://www.yoursite.com';
$html_fix = str_replace('src="',"src=\"{$urlbase}",$html);
[edited by: eelixduppy at 10:04 pm (utc) on Feb 5, 2010]
[edit reason] disabled smileys [/edit]
$str=preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\s|\+)[^"]*"))#','$1="http://example.com/$2$3',$str);
[edited by: eelixduppy at 10:04 pm (utc) on Feb 5, 2010]
[edit reason] disabled smileys [/edit]
<?php
header("content-type:text/html");
//
$regex = '(href|src)\s*=\s*"*\'*\/*([^"\'\s\>]+)(.*?)\s*\/*\s*\>';
//
$str='<div style="text-align: center;"><img width="604" height="351"
src="/userfiles/image/XOM02_01_10.jpg" alt="" /><br />';
echo htmlentities($str) . '<br><br>';
echo (preg_match("/$regex/i",$str))?"MATCH<br><br>":"NO MATCH<br><br>";
$str=preg_replace("/$regex/i","$1=\"http://example.com/$2\"$3>",$str);
echo htmlentities($str) . '<br><br>';
//
$str='<img width="604" height="351" alt="" src="userfiles/blah/bleah.jpg"><br>';
echo htmlentities($str) . '<br><br>';
echo (preg_match("/$regex/i",$str))?"MATCH<br><br>":"NO MATCH<br><br>";
$str=preg_replace("/$regex/i","$1=\"http://example.com/$2\"$3>",$str);
echo htmlentities($str) . '<br><br>';
//
$str='<img width=604 height=351 src=userfiles/blah/bleah.jpg><br>';
echo htmlentities($str) . '<br><br>';
echo (preg_match("/$regex/i",$str))?"MATCH<br><br>":"NO MATCH<br><br>";
$str=preg_replace("/$regex/i","$1=\"http://example.com/$2\"$3>",$str);
echo htmlentities($str) . '<br><br>';
//
$str="<img width='604' height='351' src='userfiles/blah/bleah.jpg'><br>";
echo htmlentities($str) . '<br><br>';
echo (preg_match("/$regex/i",$str))?"MATCH<br><br>":"NO MATCH<br><br>";
$str=preg_replace("/$regex/i","$1=\"http://example.com/$2\"$3>",$str);
echo htmlentities($str) . '<br><br>';
?>