我正在尝试解析一个字符串,但返回的内容不正确,我试图从 doc=? 中提取问号?和幻灯片=?,但相反我得到
文档编号: &doc=9729&slide=214679&#doc=9729&slide=21
幻灯片 ID: &slide=214679&#doc=9729
细绳 :
http://securefinder.com/ajax_query/delimiter.aspx?q=LNG&f=1.1&doc=9729&slide=214679&#doc=9729&slide=214679&
似乎它不接受 & 作为分隔符。
<?php
function from_to($string, $from, $to) {
//Calculate where each substring is found inside of $string
$pos_from = strpos($string, $from);
$pos_to = strpos($string, $to);
//The function will break if $to appears before $from, throw an exception.
if ($pos_from > $pos_to) {
}
return substr(
$string,
$pos_from, //From where the $from starts (first character of $from)
$pos_to - $pos_from + strlen($to) //To where the $to ends. (last character of $to)
);
}
$str = "http:/securefinder.com/ajax_query/delimiter.aspx?q=LNG&f=1.1&doc=9729&slide=214679&#doc=9729&slide=214679&";
$doc_id = from_to($str, 'doc=', '&');
$slide_id = from_to($str, 'slide=', '&');
echo 'doc id:' . $doc_id ;
echo 'slide id:'. $slide_id;
?>