开发者

PHP Simple Wiki Parser requires NOWIKI Tag

I've got a simple function that converts plain text into a wiki markup. But I faced a problem where I'm unable to prevent certain strings from modification. So I need additional nowiki tag, within which no changes are made. I'm not very familiar with regex so help will be appreciated.

<?php
function simpleText($text){
 $text = preg_replace('/======(.*?)======/', '<h5>$1</h5>', $text);
 $text = preg_replace('/=====(.*?)=====/', '<h4>$1</h4>', $text);
开发者_如何学C $text = preg_replace('/===(.*?)===/', '<h3>$1</h3>', $text);
 $text = preg_replace('/==(.*?)==/', '<h2>$1</h2>', $text);
 $text = preg_replace('/==(.*?)==/', '<h1>$1</h1>', $text);
 $text = preg_replace("/\*\*(.*?)\*\*/", '<b>$1</b>', $text);
 $text = preg_replace("/__(.*?)__/", '<u>$1</u>', $text);
 $text = preg_replace("/\/\/(.*?)\/\//", '<em>$1</em>', $text);
 $text = preg_replace('/\-\-(.*?)\-\-/', '<strike>$1</strike>', $text);
 $text = preg_replace('/\[\[Image:(.*?)\|(.*?)\]\]/', '<img src="$1" alt="$2" title="$2" />', $text);
 $text = preg_replace('/\[(.*?) (.*?)\]/', '<a target="_blank" href="$1" title="$2">$2</a>', $text);
 $text = preg_replace('/&gt;(.*?)\n/', '<blockquote>$1</blockquote>', $text);

 $text = preg_replace('/\* (.*?)\n/', '<ul><li>$1</li></ul>', $text);
 $text = preg_replace('/<\/ul><ul>/', '', $text);

 $text = preg_replace('/# (.*?)\n/', '<ol><li>$1</li></ol>', $text);
 $text = preg_replace('/<\/ol><ol>/', '', $text);

 $text = '<div class="wikiText">'.$text.'</div>';
 return $text;
}                                                                                          
?>


You can use (?!ignore)

 $text = preg_replace('(?!--)/======(.*?)======/(?!--)', '<h5>$1</h5>', $text);

Would exclude the header from being parsed if it was enclosed with '--' each end.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜