[請益] 字串正規化請益(新手)

看板PHP作者 (彭太君)時間12年前 (2013/07/16 21:13), 編輯推噓1(105)
留言6則, 4人參與, 最新討論串1/1
請問各位一個問題 如果我有一串字串像是這樣 http://localhost/xxx/yyy 要怎麼做才能變成 <http://localhost/xxx/yyy> 這樣勒? 我之前嘗試過用 function _show_sparql_replace_str_1($urlStr) { $replace = '<'; $result = preg_replace('/^h/', $replace, $urlStr); return $result; } function _show_sparql_replace_str_2($urlStr) { $replace = '>'; $result = preg_replace('/$\s/', $replace, $urlStr); return $result; } 可是這兩個function似乎沒有作用 麻煩各位了 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.129.20.134

07/16 21:17, , 1F
這, $str = "<$str>" ...不是比較快. 還是你要一篇文裡的url
07/16 21:17, 1F

07/16 21:17, , 2F
return "<".$urlStr.">"; (我真的不是來亂的)
07/16 21:17, 2F

07/16 21:18, , 3F
慢樓上一步 XD
07/16 21:18, 3F

07/16 21:18, , 4F
preg_replace('/(http:\/\/.*?)[\s]/', "<\\1>")'
07/16 21:18, 4F

07/16 21:21, , 5F
喔喔~~謝謝各位大大幫我突破盲點阿!!!!
07/16 21:21, 5F

07/16 21:45, , 6F
看來是想太多了,最多就是用一下StriStr判斷有沒有罷了
07/16 21:45, 6F
文章代碼(AID): #1HvKRco5 (PHP)
文章代碼(AID): #1HvKRco5 (PHP)