希望这就是你要找的。
$str = "//Hello World/theEnd!";
echo $str . "<br>";
$str = trim($str,"/");
$str = "http://" . $str;
echo $str;
给你http://Hello World/theEnd!
如果你想变得花哨,你也可以把它作为一个循环。
function addhttp($url) {
$url = trim($url,"/");
if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
$url = "http://" . $url;
}
return $url;
}
$add = "/media/images/CmsPageModuleDataItem/62/6260.0_gefro-suppennudeln.jpg";
$add1 = "//cdn.abc.de/images/100/3/7/1/5/0/8/371508F1.jpg";
$add2 = "http://s7.abc.com/is/image/LandsEnd/461469_FG16_LF_616";
echo "<br />";
echo addhttp($add);
echo "<br />";
echo addhttp($add1);
echo "<br />";
echo addhttp($add2);
这给了你
http://media/images/CmsPageModuleDataItem/62/6260.0_gefro-suppennudeln.jpg
http://cdn.abc.de/images/100/3/7/1/5/0/8/371508F1.jpg
http://s7.abc.com/is/image/LandsEnd/461469_FG16_LF_616