久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

PHP利用正則表達式將相對路徑轉成絕對路徑的方法示例

這篇文章主要介紹了PHP利用正則表達式將相對路徑轉成絕對路徑的方法,文中給出了詳細的示例代碼,大家可以整合成一個方法,在需要的地方調用,非常的不錯。需要的朋友們下面來

前言

大家應該都有所體會,很多時候在做網絡爬蟲的時候特別需要將爬蟲搜索到的超鏈接進行處理,統一都改成絕對路徑的,所以本文就寫了一個正則表達式來對搜索到的鏈接進行處理。下面話不多說,來看看詳細的介紹吧。

通常我們可能會搜索到如下的鏈接:

<!-- 空超鏈接 -->
<a href=""></a> 
<!-- 空白符 -->
<a href=" " rel="external nofollow" > </a>
<!-- a標簽含有其它屬性 -->
<a href="index.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" alt="超鏈接"> index.html </a>
<a href="/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_blank"> / target="_blank" </a>
<a target="_blank" href="/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" alt="超鏈接" > target="_blank" / alt="超鏈接" </a>
<a target="_blank" title="超鏈接" href="/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" alt="超鏈接" > target="_blank" title="超鏈接" / alt="超鏈接" </a>
<!-- 根目錄 -->
<a href="/" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" > / </a>
<a href="a" rel="external nofollow" > a </a>
<!-- 含參數 -->
<a href="/index.html?id=1" rel="external nofollow" > /index.html?id=1 </a>
<a href="?id=2" rel="external nofollow" > ?id=2 </a>
<!-- // -->
<a  rel="external nofollow" > //index.html </a>
<a  rel="external nofollow" > //www.mafutian.net </a>
<!-- 站內鏈接 -->
<a  rel="external nofollow" > http://www.hole_1.com/index.html </a>
<!-- 站外鏈接 -->
<a  rel="external nofollow" > http://www.mafutian.net </a>
<a  rel="external nofollow" > http://www.numberer.net </a>
<!-- 圖片,文本文件格式的鏈接 -->
<a href="1.jpg" rel="external nofollow" > 1.jpg </a>
<a href="1.jpeg" rel="external nofollow" > 1.jpeg </a>
<a href="1.gif" rel="external nofollow" > 1.gif </a>
<a href="1.png" rel="external nofollow" > 1.png </a>
<a href="1.txt" rel="external nofollow" > 1.txt </a>
<!-- 普通鏈接 -->
<a href="index.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" > index.html </a>
<a href="index.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" > index.html </a>
<a href="./index.html" rel="external nofollow" > ./index.html </a>
<a href="../index.html" rel="external nofollow" > ../index.html </a>
<a href=".../" rel="external nofollow" > .../ </a>
<a href="..." rel="external nofollow" > ... </a>
<!-- 非鏈接,含有鏈接冒號 --> 
<a href="javascript:void(0)" rel="external nofollow" > javascript:void(0) </a>
<a href="a:b" rel="external nofollow" > a:b </a>
<a href="/a#a:b" rel="external nofollow" > /a#a:b </a>
<a href="mailto:'mafutian@126.com'" rel="external nofollow" > mailto:'mafutian@126.com' </a>
<a href="/tencent://message/?uin=335134463" rel="external nofollow" > /tencent://message/?uin=335134463 </a> 
<!-- 相對路徑 -->
<a href="." rel="external nofollow" > . </a>
<a href=".." rel="external nofollow" > .. </a>
<a href="../" rel="external nofollow" > ../ </a>
<a href="/a/b/.." rel="external nofollow" > /a/b/.. </a>
<a href="/a" rel="external nofollow" > /a </a>
<a href="./b" rel="external nofollow" > ./b </a>
<a href="./././././././././b" rel="external nofollow" > ./././././././././b </a> <!-- 其實就是 ./b -->
<a href="../c" rel="external nofollow" > ../c </a>
<a href="../../d" rel="external nofollow" > ../../d </a>
<a href="../a/../b/c/../d" rel="external nofollow" > ../a/../b/c/../d </a>
<a href="./../e" rel="external nofollow" > ./../e </a>
<a  rel="external nofollow" > http://www.hole_1.org/./../e </a> 
<a href="./.././f" rel="external nofollow" > ./.././f </a>
<a  rel="external nofollow" > http://www.hole_1.org/../a/.../../b/c/../d/.. </a> 
<!-- 帶有端口號 -->
<a href=":8081/index.html" rel="external nofollow" > :8081/index.html </a>
<a  rel="external nofollow" > :80/index.html </a>
<a  rel="external nofollow" > http://www.mafutian.net:8081/index.html </a>
<a  rel="external nofollow" > http://www.mafutian.net:8082/index.html </a>

處理的第一步,設置成絕對路徑:

http:// ... / ../ ../
【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。

相關文檔推薦

這篇文章主要介紹了PHP實現正則表達式分組捕獲操作,結合實例形式分析了php正則表達式獲取分組捕獲操作的相關實現方法與使用注意事項,需要的朋友可以參考下
這篇文章主要介紹了phpstorm 正則匹配刪除空行、注釋行,需要的朋友可以參考下
為了我們的隱私,所以我們把手機號碼部分數字隱藏掉,今天小編給大家帶來了PHP利用正則表達式實現手機號碼中間4位用星號(*)替換顯示,需要的朋友參考下吧
這篇文章通過實例代碼給大家介紹了php表單習慣使用的正則表達式,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
這篇文章主要介紹了PHP實現將標點符號正則替換為空格的方法,結合實例形式分析了php針對符號的正則匹配相關操作技巧,需要的朋友可以參考下
這篇文章主要介紹了PHP正則匹配操作,結合簡單實例形式分析了php中preg_match_all針對HTML標簽中P元素及img src元素內容的獲取技巧,需要的朋友可以參考下
主站蜘蛛池模板: 久久久久中文字幕 | 人人艹人人爽 | 国产一区2区 | 黄网站涩免费蜜桃网站 | 久久av网| 欧美亚洲国产一区二区三区 | 日韩电影中文字幕 | 天天草草草| 亚洲一区二区久久 | 欧美日韩中文字幕在线播放 | 久久精品国产一区 | 日韩三级在线观看 | 欧美中文 | 性欧美精品一区二区三区在线播放 | 18性欧美| 亚洲久草| 天堂网中文字幕在线观看 | 视频一区二区三区中文字幕 | 91黄色免费看 | 欧美日韩亚洲国产 | 欧美在线一区二区三区 | 精品日韩在线 | 久久久久亚洲 | 亚洲精品一区在线 | 午夜不卡一区二区 | 亚洲一区二区三区观看 | 午夜一级大片 | 中文字幕亚洲一区 | 国产美女自拍视频 | 欧美在线视频一区 | 精品一区二区三区91 | 男女午夜激情视频 | 亚洲一区 中文字幕 | 日韩精品免费视频 | 在线一区视频 | 欧美一区视频 | 日韩精品一区二区三区在线观看 | 九九九国产 | 国产一级视频免费播放 | 免费的一级视频 | 免费视频一区二区三区在线观看 |