Who can help me find a better way to use php to extract the content between urscsi and & amp; saU in the following string {code ...} who can help me find a better way to use php to extract the content between urscsi = and & sa = U in the following string?
urlq=https://zh.wikipedia.org/zh/test&sa=U&ved=0ahUKEwjZyO_jtvTKAhXFGh4KHVPkA70QFggeMAE&usg=AFQjCNET0LD_wKKA7nfCkcC44Oii6I13nQ
Reply content:
Who can help me find a better way to use php to extract the content between urscsi = and & sa = U in the following string?
urlq=https://zh.wikipedia.org/zh/test&sa=U&ved=0ahUKEwjZyO_jtvTKAhXFGh4KHVPkA70QFggeMAE&usg=AFQjCNET0LD_wKKA7nfCkcC44Oii6I13nQ
Regular Expression
$str = 'urlq=https://zh.wikipedia.org/zh/test&sa=U&ved=0ahUKEwjZyO_jtvTKAhXFGh4KHVPkA70QFggeMAE&usg=AFQjCNET0LD_wKKA7nfCkcC44Oii6I13nQ';preg_match("/urlq=(.*?)&sa/", $str, $a);$b = $a[1];echo $b;
Split
$str = 'urlq=https://zh.wikipedia.org/zh/test&sa=U&ved=0ahUKEwjZyO_jtvTKAhXFGh4KHVPkA70QFggeMAE&usg=AFQjCNET0LD_wKKA7nfCkcC44Oii6I13nQ';$str1 = explode('urlq=', $str);$str2 = explode('&sa', $str1[1]);$b = $str2[0];echo $b;
Check whether the parse_url function works.
Give you a UDF
// $ Kw1 is the string to be intercepted // $ mark1 start character // $ mark2 is the ending character // returns an intercepted string // function getNeedBetween ($ kw1, $ mark1, $ mark2) {$ kw = $ kw1; $ kw = '000000 '. $ kw. '20140901'; $ st = stripos ($ kw, $ mark1); $ ed = stripos ($ kw, $ mark2 ); if ($ st = false | $ ed = false) | $ st >=$ ed) return 0; $ kw = substr ($ kw, ($ st + 1), ($ ed-$ ST-1); return $ kw ;}