php 使用pathinfo(), parse_url(), basename()解析URL

本文章向你們介紹解析URL的三種方法,分別爲pathinfo()方法、parse_url()方法和basename()方法。每一個方法都列舉了一個實例,經過實例更容易理解這三個函數的使用方法和技巧,須要的朋友能夠參考一下。
一、利用pathinfo解析URL

<?
    /* by www.manongjc.com/article/1119.html */
    $test = pathinfo("http://localhost/index.php");
    print_r($test);
?>


結果以下
Array
(
 [dirname] => http://localhost //url的路徑
 [basename] => index.php //完整文件名
 [extension] => php //文件名後綴
 [filename] => index //文件名
)


 


二、利用parse_url()函數解析


<?
    /* by http://www.manongjc.com     (碼農教程)*/
    $test = parse_url("http://localhost/index.php?name=tank&sex=1#top");
    print_r($test);
?>


結果以下
Array
(
 [scheme] => http //使用什麼協議
 [host] => localhost //主機名
 [path] => /index.php //路徑
 [query] => name=tank&sex=1 // 所傳的參數
 [fragment] => top //後面根的錨點
)


 


三、使用basename()解析


<?
    $test = basename("http://localhost/index.php?name=tank&sex=1#top");
    echo $test;
?>


結果以下

index.php?name=tank&sex=1#topphp


原文地址:http://www.manongjc.com/article/1119.html
html


其餘閱讀:mysql

  • php鏈接數據庫服務器並選擇數據庫操做實例
  • php使用mysql_result()函數解析結果集數據
  • php mysql_result()函數使用實例
  • php mysql_real_escape_string addslashes及mysql綁定參數防SQL注入攻擊
  • php mysql_real_escape_string構建安全的SQL語句
  • 相關文章
    相關標籤/搜索