php怎麼用正則取出網址中某個引數?
阿新 • • 發佈:2018-11-10
$str = <<<TEXT 如下類似網址: https://v.qq.com/iframe/player.html?vid=j00169ib5er&tiny=0&auto=0 https://v.qq.com/iframe/player.html?vid=x00243heka3&tiny=0&auto=0 TEXT; preg_match_all("#\?vid\=(.+?)&#",$str,$arr); echo '<pre>'; var_dump($arr[1]); echo '</pre>'; /* array (size=2) 0 => string 'j00169ib5er' (length=11) 1 => string 'x00243heka3' (length=11)*/
方法二; $str="https://v.qq.com/iframe/player.html?vid=j00169isdfsdsb5er&tiny=0&auto=0"; preg_match_all("/vid=([\s\S]*?)&/",$str,$arr); print_r($arr);
如下類似網址:
https://v.qq.com/iframe/player.html?vid=j00169ib5er&tiny=0&auto=0
https://v.qq.com/iframe/player.html?vid=x00243heka3&tiny=0&auto=0
怎麼用正則取出紅色位置的引數?
即可以得到vid=和&中間的引數,謝謝!