<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li><span>$</span><span class="attribute">url</span><span> = </span><span class="attribute-value">'http://username:password<br />@hostname/path?arg=value#anchor'</span><span>; </span></li><li class="alt"><span>print_r(parse_url($url)); </span></li><li><span>echo parse_url($url, PHP_URL_PATH); </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li></ol>出力:
<ol class="dp-xml"> <li class="alt"><span><span>Array </span></span></li> <li><span>( </span></li> <li class="alt"> <span>[scheme] =</span><span class="tag">></span><span> http </span> </li> <li> <span>[host] =</span><span class="tag">></span><span> hostname </span> </li> <li class="alt"> <span>[user] =</span><span class="tag">></span><span> username </span> </li> <li> <span>[pass] =</span><span class="tag">></span><span> password </span> </li> <li class="alt"> <span>[path] =</span><span class="tag">></span><span> /path </span> </li> <li> <span>[query] =</span><span class="tag">></span><span> </span><span class="attribute">arg</span><span>=</span><span class="attribute-value">value</span><span> </span> </li> <li class="alt"> <span>[fragment] =</span><span class="tag">></span><span> anchor </span> </li> <li><span>) </span></li> </ol>
echo parse_url($url, PHP_URL_PATH); を設定するなど、指定された部分を抽出することも簡単です。次のパラメータ:
PHP_URL_SCHEME、PHP_URL_HOST、PHP_URL_PORT、PHP_URL_USER、PHP_URL_PASS、PHP_URL_PATH、PHP_URL_QUERY、または PHP_URL_FRAGMENT。
http://www.bkjia.com/PHPjc/445957.html
www.bkjia.com
http://www.bkjia.com/PHPjc/445957.html