Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just use a single <code>preg_replace()</code> function with the <a href="http://php.net/manual/en/reference.pcre.pattern.modifiers.php" rel="nofollow">e modifier</a> to execute an <code>htmlenteties()</code> function on everything it finds within <code>&lt;code&gt;</code> tags</p> <p>EDITED</p> <pre><code>function allowedHtml($str) { $str = htmlentities($str, ENT_QUOTES, "UTF-8"); $allowed_tags = array("b", "strong", "i", "em", "code"); foreach ($allowed_tags as $tag) { $str = preg_replace("#&amp;lt;" . $tag . "&amp;gt;(.*?)&amp;lt;/" . $tag . "&amp;gt;#i", "&lt;" . $tag . "&gt;$1&lt;/" . $tag . "&gt;", $str); } return $str; } $reply = allowedHtml($_POST['reply']); $reply = preg_replace("#\&lt;code\&gt;(.+?)\&lt;/code\&gt;#e", "'&lt;code&gt;'.htmlentities('$1', ENT_QUOTES, 'UTF-8').'&lt;/code&gt;'", $reply); $reply = str_replace("&amp;amp;", "&amp;", $reply); </code></pre> <p>Rewrote your <code>allowedHtml()</code> function and added a <code>str_replace()</code> at the end.</p> <p>It's tested and should now work perfectly :)</p> <p>UPDATED - NEW SOLUTION</p> <pre><code>function convertHtml($reply, $revert = false) { $specials = array("**", "*", "_", "-"); $tags = array("b", "i", "u", "s"); foreach ($tags as $key =&gt; $tag) { $open = "&lt;" . $tag . "&gt;"; $close = "&lt;/" . $tag . "&gt;"; if ($revert == true) { $special = $specials[$key]; $reply = preg_replace("#" . $open . "(.+?)" . $close . "#i", $special . "$1" . $special, $reply); } else { $special = str_replace("*", "\*", $specials[$key]); $reply = preg_replace("#" . $special . "(.+?)" . $special . "#i", $open . "$1" . $close, $reply); } } return $reply; } $reply = htmlentities($reply, ENT_QUOTES, "UTF-8"); $reply = convertHtml($reply); $reply = preg_replace("#[^\S\r\n]{4}(.+?)(?!.+)#i", "&lt;pre&gt;&lt;code&gt;$1&lt;/code&gt;&lt;/pre&gt;", $reply); $reply = preg_replace("#\&lt;/code\&gt;\&lt;/pre\&gt;(\s*)\&lt;pre\&gt;\&lt;code\&gt;#i", "$1", $reply); $reply = nl2br($reply); $reply = preg_replace("#\&lt;pre\&gt;\&lt;code\&gt;(.*?)\&lt;/code\&gt;\&lt;/pre\&gt;#se", "'&lt;pre&gt;&lt;code&gt;'.convertHtml(str_replace('&lt;br /&gt;', '', '$1'), true).'&lt;/code&gt;&lt;/pre&gt;'", $reply); </code></pre> <p>Discussed another solution, and the above code will fix that. It works just like the Stack Overflow html conversion, which means that ** becomes bold, * becomes italic, _ becomes underlined and - is "strikethrough". On top of that, all lines starting with 4 or more spaces will be output as code</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload