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

php html 從文本創建鏈接

php html create link from text(php html 從文本創建鏈接)
本文介紹了php html 從文本創建鏈接的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我找到了在文本中找到鏈接時創建 html 鏈接的例程

I found a routine to create a html link when a link is found in a text

 <?php
 function makelink($text) 
 {
 return preg_replace('/(http://[a-zA-Z0-9_-.]*?) /i', '<a href="$1">$1</a> ', $text." "); 
 } 

 // works
 echo makelink ("hello how http://www.guruk.com ");

 // dont work
 echo makelink ("hello how http://www.guruk.com/test.php ");

?>

如您在示例中所見,它僅適用于域,而不適用于該鏈接中存在頁面或子目錄的情況.

as you see in the example, it works find with a domain only, not when there is a page or subdirectory is within that link.

您能否為該功能提供一個解決方案,使其也適用于頁面和子目錄?

Can you provide a solution for that function to work also with pages and subdirs?

謝謝克里斯

推薦答案

字符 ?=& 用于帶有查詢字符串的 url.請注意,我將分隔符從 / 更改為 ! 因為您的表達式中有很多斜線.另請注意,如果您處于不區分大小寫的模式,則不需要 A-Z.

The characters ?=& are for urls with query strings. Notice that I changed the separator from / to ! because there a lot of slashes in your expression. Also note that you don't need A-Z if you are in case-insensitive mode.

return preg_replace('!(http://[a-z0-9_./?=&-]+)!i', '<a href="$1">$1</a> ', $text." ");

這篇關于php html 從文本創建鏈接的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 精品国产一区二区国模嫣然 | 国产一区二区免费 | 成人国产精品一级毛片视频毛片 | 久久精品69 | 91在线一区| 国产激情视频在线 | 国产精品久久久久久影视 | 我要看黄色录像一级片 | 国产精品免费一区二区三区 | 五月天国产在线 | 国产精品伦理一区 | 国产精品久久久久久吹潮 | 国产日韩欧美一区二区 | 欧美精品一区二区三区在线播放 | 成人在线网 | 国产成人精品区一区二区不卡 | 手机在线观看av | 亚洲午夜精品视频 | 国产午夜精品一区二区三区四区 | 午夜精品一区二区三区在线观看 | 久久av网| 性视频一区 | 黄色片网此 | 午夜影院在线观看免费 | 精品久久久久久亚洲精品 | 成人av在线播放 | 国产精品国产三级国产aⅴ无密码 | 欧美视频成人 | 久久se精品一区精品二区 | 欧美日韩一区精品 | 久热精品在线观看视频 | 草逼网站 | 亚洲狠狠 | 国产精品欧美一区二区三区不卡 | 高清久久久 | 羞羞视频网站在线观看 | 免费视频一区 | 999国产视频 | 老司机深夜福利网站 | 天天干视频网 | 国产精品久久久久一区二区三区 |