我使用了以下功能:简单的wiki分析器和链接自动检测
function MakeLinks($source){
return preg_replace('!(((f|ht){1}tp://)[-a-zA-Zа-яА-Я()[email protected]:%_+.~#?&;//=]+)!i', '<a href="/1">$1</a>', $source);
}
function simpleWiki($text){
$text = preg_replace('/\[\[Image:(.*)\]\]/', '<a href="$1"><img src="$1" /></a>', $text);
return $text;
}
第一个转换成http://example.com
链接http://example.com。
第二个函数将像[[Image:http://example.com/logo.png]]
这样的字符串转换为图像。
现在,如果我有一个文本
$text = 'this is my image [[Image:http://example.com/logo.png]]';
,并将其转换这样simpleWiki(makeLinks($text))
它输出类似于:
this is my image <a href="url"><img src="<a href="url">url</a>"/></a>
我如何避免这种情况?如何检查该URL是不是[[Image:URL]]
构造的一部分?
:'{1}'是从来没有需要的:它只是乱七八糟的正则表达式。 – 2011-03-12 14:02:24