我想改變字串中的單詞,我知道laravel Str::replace()函式,但是如果你寫的是精確的單詞,它就會轉換。這是我想做的 :
$string = " 這是@username,這是@username2"
我想找到以"@"開頭的用戶名,并使它們像下面一樣,我想給它們加上<strong>html標簽:
$newstring = " This is <strong>@username</strong> and this is <strong>@username2</strong> "
我找不到改變str替換動態值的方法。
謝謝
uj5u.com熱心網友回復:
使用preg_replace
$string = 'this is @username and this is @username2'。
$newString = preg_replace('/(@w )/', '<strong>$1</strong>', $string) 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/307884.html
標籤:
下一篇:攝像機影像的位圖訪問違規例外
