我想弄清楚一个字符串是否包含多于1个http://
像这样:
http://uploading.com/files/c8e99378/image-slider-skins.zip/http://www.filesonic.com/file/3524497744/image-slider-skins.zip
我知道如何判断它是否存在,但如何在第二个http
的开头分割字符串?
答案 0 :(得分:1)
$parts = explode('http://', $str);
$secondPart = 'http://'.$parts[2];
echo $secondPart;
文档中的更多信息
或其他一些方法(更简单,更快速):
$firstPart = substr($str, 0, strpos($str, 'http://', 8));
或者你也可以使用我不推荐的REGEX,因为这个简单的任务很重要:
if (preg_match('/(http:\/\/.*)(?=http:\/\/)/', $str, $matches)) {
echo $matches[1];
}
答案 1 :(得分:0)
使用explode
$parts = explode('http://', $string);
您也可以直接将部分结果提取到变量中:
list($part1, $part2) = explode('http://', $string);