資料來源:http://php.net/manual/en/function.preg-match.php

<?php
$pattern = '`^((?P<protocol>[^:/?#]+):)?(//(?P<host>[^/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<label>.*))?`i';
$subject = 'http://example.com/defg/abcd/index.php?m=1&b=2#taichunmin';
preg_match($pattern,$subject,$match);
//可取用的資料如下
echo 'protocol = '  .$match['protocol']. '<br />';
echo 'host = '      .$match['host'    ]. '<br />';
echo 'path = '      .$match['path'    ]. '<br />';
echo 'query = '     .$match['query'   ]. '<br />';
echo 'label = '     .$match['label'   ]. '<br />';
?>
arrow
arrow
    文章標籤
    php preg url
    全站熱搜

    和風信使 發表在 痞客邦 留言(0) 人氣()