当我对单个字符串使用strpos()时,它工作正常但是当我从URL获取html并将此html传递给此函数时,此错误显示。我无法理解这背后的原因。请有人解释这个警告吗?
$html = file_get_content("site URL");
function getHtml ($html, $startTag, $endTag, $start) {
$tagStart = strpos($html, $startTag) + $start;
$tagEnd = strpos($html, $endTag, $tagStart);
return substr($html, $tagStart, $tagEnd - $tagStart);
}
并且错误指向此函数中的$ tagEnd行。
答案 0 :(得分:1)
如果偏移量不在0和字符串长度之间,则此函数会发出警告:
Warning: strpos(): Offset not contained in string in ...