0

Right, basically I'm trying to create a function that will I can use to change user inputted tags like [b][/b] to strong -- /strong etc.

function wrap(){
    $content = 'Text [b]here[/b]... ';

    $replace = str_replace("[b]", "<strong>", $content);
    $replace = str_replace("[/b]", "</strong>", $content);
    echo $replace;  
}

When the user submits a new post, customising it using bold tags, em.. it will get displayed on the view post page...

<?php echo wrap("$post->postContent"); ?>

My question is how do I get this to work... I want to be able to create several replacements and just wrap each php echo with the function.

I've been playing with tons of alternative methods of code but none have proven to be completely successful.


Irrelevant but possibly useful information.

  • OS: OS X Mavericks 10.9.2 (MacBook Pro)
  • PHP Version 5.5.10 (MAMP PRO 3)
  • Sublime Text 3 (Editor)
4

1 回答 1

2

这个用例(即解析复杂的标记语言)不是一个str_replace适合的用例。

此外,如果不转义 HTML 实体,您会让自己容易受到XSS的攻击,等等。

您应该使用BBCode 解析器

于 2014-08-13T14:43:41.740 回答