0
我有這樣的代碼,以使可點擊的鏈接到我的應用程序:的preg_replace和Twitter
$string = preg_replace('!(((f|ht)tp://)[-a-zA-Zа-яА-Я()[email protected]:%_+.~#?&;//=]+)!i', '<a href="$1" rel="nofollow">$1</a>', $string);
$string = preg_replace('/@(\w+)/', '<a href="http://twitter.com/$1" rel="nofollow">$0</a>', $string);
$string = preg_replace('/#(\w+)/', '<a href="http://search.twitter.com/search?q=%23$1" rel="nofollow">$0</a>', $string);
上面的代碼工作正常,但突然間林看到這樣http://twitter.com/#!/username
和http://domain.com/[email protected]/
一些鏈接,打破一切,任何知道如何解決我的代碼?
串VAR直接來自Twitter的API,這裏有一個例子:$string = 'http://twitter.com/!#/metallica http://someurl.com/[email protected]/ ';
在此先感謝。 已編輯:添加字符串值。
嘗試'(((F | HT)TP://)[-a-ZA-Zа-яА-Я()0-9 @ :%_ +。〜#?&; // =!*] +)!i'作爲您的正則表達式。 – erisco 2011-04-17 04:48:17
你可以提出'$ string'的值嗎? – 2011-04-17 04:49:59
@erisco謝謝,但我得到這個錯誤:未知修飾符'*'/ @ experimentX你是什麼意思? – greenbandit 2011-04-17 04:51:39