Php 将正则表达式更改为不包含[and]中的内容
我这里有一个自动链接的正则表达式代码:Php 将正则表达式更改为不包含[and]中的内容,php,regex,Php,Regex,我这里有一个自动链接的正则表达式代码: // turn any url into url bbcode that doesn't have it already - so we can auto link urls- thanks stackoverflow $URLRegex = '/(?:(?<!(\[\/url\]|\[\/url=))(\s|^))'; // No [url]-tag in front and is start of string, or has whitespa
// turn any url into url bbcode that doesn't have it already - so we can auto link urls- thanks stackoverflow
$URLRegex = '/(?:(?<!(\[\/url\]|\[\/url=))(\s|^))'; // No [url]-tag in front and is start of string, or has whitespace in front
$URLRegex.= '('; // Start capturing URL
$URLRegex.= '(https?|ftps?|ircs?):\/\/'; // Protocol
$URLRegex.= '\S+'; // Any non-space character
$URLRegex.= ')'; // Stop capturing URL
$URLRegex.= '(?:(?<![.,;!?:\"\'()-])(\/|\s|\.?$))/i'; // Doesn't end with punctuation and is end of string, or has whitespace after
$body = preg_replace($URLRegex,"$2[url=$3]$3[/url]$5", $body);
正确的输出是:
<div class="quote"><strong>Quote from liamdawe</strong><br /> Have you had a look at <a href="http://pcgamingwiki.com/wiki/Serious_Sam_II#Linux_Installation" target="_blank">this howto</a>? <img src="/jscripts/sce/emoticons/smile.png" alt="" /><br />
<br />
<a href="http://pcgamingwiki.com/wiki/Serious_Sam_II#Linux_Installation" target="_blank">http://pcgamingwiki.com/wiki/Serious_Sam_II#Linux_Installation</a></div><br />
Testing
引用liamdawe
你看过吗
测试
但我得到的结果是:
<div class="quote"><strong>Quote from liamdawe</strong><br /> Have you had a look at <a href="http://pcgamingwiki.com/wiki/Serious_Sam_II#Linux_Installation" target="_blank">this howto</a>? <img src="/jscripts/sce/emoticons/smile.png" alt="" /><br />
<br />
<a href="http://pcgamingwiki.com/wiki/Serious_Sam_II#Linux_Installation </div>" target="_blank">http://pcgamingwiki.com/wiki/Serious_Sam_II#Linux_Installation[/quote]</a><br />
Testing<br />
引用liamdawe
你看过吗
测试
正如您所见,它在链接中包含了[/quote]标记,因为它没有忽略自动链接器regex中的bbcode标记
如果需要,下面是执行该类型报价的代码:
//引用真实的人、书或任何东西
$pattern='/[quote\=(.+?)](.+?)[/quote]/is'
$replace = "<div class=\"quote\"><strong>Quote from $1</strong><br />$2</div>";
while(preg_match($pattern, $body))
{
$body = preg_replace($pattern, $replace, $body);
}
$replace=“引用$1
$2”;
while(preg_match($pattern,$body))
{
$body=preg_replace($pattern,$replace,$body);
}
试试这个
$URLRegex = '/(?:(?<!(\[\/url\]|\[\/url=))(\s|^))'; // No [url]-tag in front and is start of string, or has whitespace in front
$URLRegex.= '('; // Start capturing URL
$URLRegex.= '(https?|ftps?|ircs?):\/\/'; // Protocol
$URLRegex.= '[\w\d\.\/#\_\-\?:=]+'; // Any non-space character
$URLRegex.= ')'; // Stop capturing URL
$URLRegex.= '(?:(?<![.,;!?:\"\'()-])(\/|\[|\s|\.?$))/i'; // Doesn't end with punctuation and is end of string, or has whitespace after
$body = preg_replace($URLRegex,"$2[url=$3]$3[/url]$5", $body);
$URLRegex='/(?:(?请给我们显示前后的代码。这是不相关的。这是做链接的所有代码。那么给你任何帮助都不相关。你能给我们一个示例输入、当前输出和所需输出吗?添加了示例,添加了引号代码,以显示它是如何完成的(如果需要)。
$URLRegex = '/(?:(?<!(\[\/url\]|\[\/url=))(\s|^))'; // No [url]-tag in front and is start of string, or has whitespace in front
$URLRegex.= '('; // Start capturing URL
$URLRegex.= '(https?|ftps?|ircs?):\/\/'; // Protocol
$URLRegex.= '[\w\d\.\/#\_\-\?:=]+'; // Any non-space character
$URLRegex.= ')'; // Stop capturing URL
$URLRegex.= '(?:(?<![.,;!?:\"\'()-])(\/|\[|\s|\.?$))/i'; // Doesn't end with punctuation and is end of string, or has whitespace after
$body = preg_replace($URLRegex,"$2[url=$3]$3[/url]$5", $body);