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

php html 從文本創(chuàng)建鏈接

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

問題描述

限時送ChatGPT賬號..

我找到了在文本中找到鏈接時創(chuàng)建 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.請注意,我將分隔符從 / 更改為 ! 因為您的表達(dá)式中有很多斜線.另請注意,如果您處于不區(qū)分大小寫的模式,則不需要 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." ");

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

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

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
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 簡單產(chǎn)品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 国产精品成人一区二区三区 | 亚洲午夜精品在线观看 | 欧美久久一区 | 亚洲区视频| 天堂一区二区三区 | 国产精品国产精品国产专区不片 | 色毛片 | 久久一| 久久久久国产精品午夜一区 | 国产在线a视频 | 四虎影院新地址 | 99reav| 中文在线一区二区 | 中文字幕一区二区三区精彩视频 | 欧美视频在线看 | 成人精品一区二区三区四区 | 一区二区三区四区在线播放 | 一区视频在线免费观看 | 久久亚洲欧美日韩精品专区 | 婷婷五月色综合 | 日韩av在线一区 | 成人国产一区二区三区精品麻豆 | 欧美一级二级视频 | 亚洲精品久久久一区二区三区 | 亚洲国产欧美精品 | 久久久久电影 | 老司机成人在线 | 午夜爽爽男女免费观看hd | 欧美爱爱视频 | 五月天婷婷激情 | 久久国产亚洲 | 午夜丰满寂寞少妇精品 | 日韩中文久久 | 日韩精品1区2区 | 一区二区av | 女女百合av大片一区二区三区九县 | 91精品国产一区二区三区 | 久久精品国产一区二区电影 | 中文字幕 国产精品 | 伊人久久大香线 | 久久精品国产亚洲夜色av网站 |