<?php
//echo $string;
function get_html($url) {
$urlnormal = str_replace("https", 'http', $url);
$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
$c = curl_init($urlnormal);
curl_setopt($c,CURLOPT_RETURNTRANSFER, true);
curl_setopt($c,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($c, CURLOPT_USERAGENT, $userAgent);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
$html = curl_exec($c);
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
return $html;
}
$start = "video","src":"";
$end =","width":320,"height"";
$s= htmlspecialchars($start);
$e=htmlspecialchars($end);
function getBetween($string, $start, $end ){
if (strpos($string, $start)) { // required if $start not exist in $string
$startCharCount = strpos($string, $start) + strlen($start);
$firstSubStr = substr($string, $startCharCount, strlen($string));
$endCharCount = strpos($firstSubStr, $end);
if ($endCharCount == 0) {
$endCharCount = strlen($firstSubStr);
}
return substr($firstSubStr, 0, $endCharCount);
}
else
{
return '';
}
}
$string = get_html('https://m.facebook.com/1995740577407064/');
echo getBetween($string,$s,$e);
?>
方法get_html()
用于获取url的html,获取HTML之后,我使用getBetween()
方法仅打印介于$start
和$end
之间的字符串。
当我只回显$ string时,链接会自动重定向到视频页面,但是当我回显getBetwwen()
方法时,它什么也没显示,我尝试了很多次但没有用,请帮忙。