我想用preg_replace
替換一些字符串,如果事情在字符串中是不存在的。也就是說,如果子字符串在那裏,字符串將不匹配。
例如,如果字符串包含.png
,它將不會找到/匹配它。
example.com/image.png
這裏,因爲字符串包含行/子.png
它不會找到它。
example.com/image
這裏,會發現它,因爲這個串不包含行/子.png
任何地方。
對於那些仍然沒有得到我的人。
$result = preg_replace("#http://(.*\S)[Something here that will not match the link if it finds the .png at last]#","<a href='\\1'>\\1</a>","Here is a link that should work http://example.com/; Here is a link that should NOT work http://example.com/image.png")
是'example.com/image'整個字符串,或者只是字符串的一部分?如果它只是字符串的一部分......找到它的標準是什麼? – 2012-09-16 15:19:49
喜歡,如果它是一個帖子:「你好,看看這個!http://example.com/image」它會找到鏈接,並使其與preg_replace鏈接,但如果它是這樣的:「你好,檢查這out!http://example.com/image.png「它只是不會做任何事情...... – do0l67
所以你想匹配的網址?你已經有了一個正式的表達方式嗎? – 2012-09-16 15:22:19