作者ycpeng0515 (彭太君)
看板PHP
標題[請益] 字串正規化請益(新手)
時間Tue Jul 16 21:13:07 2013
請問各位一個問題
如果我有一串字串像是這樣
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
1F:→ alpe:這, $str = "<$str>" ...不是比較快. 還是你要一篇文裡的url 07/16 21:17
2F:推 PsMonkey:return "<".$urlStr.">"; (我真的不是來亂的) 07/16 21:17
3F:→ PsMonkey:慢樓上一步 XD 07/16 21:18
4F:→ alpe:preg_replace('/(http:\/\/.*?)[\s]/', "<\\1>")' 07/16 21:18
5F:→ ycpeng0515:喔喔~~謝謝各位大大幫我突破盲點阿!!!! 07/16 21:21
6F:→ see7di:看來是想太多了,最多就是用一下StriStr判斷有沒有罷了 07/16 21:45