php strpos ignoring character

casamareste

New Member
I am trying to parse a string but what I get returned is incorrect , I am trying to extract just the question mark from doc=? and slide=?, but instead I get\[quote\] doc id:&doc=9729&slide=214679&#doc=9729&slide=21 slide id:&slide=214679&#doc=9729\[/quote\]string : \[quote\] http:/securefinder.com/ajax_query/delimiter.aspx?q=LNG&f=1.1&doc=9729&slide=214679&#doc=9729&slide=214679&\[/quote\]It seems it does not accept & as the delimiting character. \[code\] <?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; ?>\[/code\]
 
Back
Top