Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can PHP detect paragraphs and add <p> tags for HTML output
    primarykey
    data
    text
    <p>How do I make PHP detect paragraphs and add and parse <p> </p> tags for HTML output?</p> <p>I'm making a blog with bbcode support but I'm still missing the <p> tags in the HTML output of the blog posts. How can I make PHP detect and add <p> tags on it's output?</p> <p>I have currenly this code to parse just some basics bbcode and GeSHi code:</p> <pre><code>&lt;?php function code($match) { require_once './class/geshi/geshi.php'; $geshi = new GeSHi($match[2], $match[1]); return $geshi-&gt;parse_code(); } function bbcode($input) { $input = strip_tags($input); $input = htmlentities($input); $bbcodes = array( "/\[b\](.*?)\[\/b\]/is" =&gt; "&lt;b&gt;$1&lt;/b&gt;", "/\[u\](.*?)\[\/u\]/" =&gt; "&lt;u&gt;$1&lt;/u&gt;", "/\[i\](.*?)\[\/i\]/" =&gt; "&lt;i&gt;$1&lt;/i&gt;", "/\[d\](.*?)\[\/d\]/" =&gt; "&lt;del&gt;$1&lt;/del&gt;", "/\[url=(.*?)\](.*?)\[\/url\]/" =&gt; "&lt;a href='$1'&gt;$2&lt;/a&gt;" ); $input = preg_replace(array_keys($bbcodes), array_values($bbcodes), $input); //Check for code and add GeSHi: $input = preg_replace_callback('~\[code=(.*?)\](.*?)\[\/code\]~is', 'code', $input); return $input; } ?&gt; </code></pre> <p>If the user submits in textarea the following example:</p> <pre><code>This is [b]bold and [i]italic[/i][/b]. This is some [u]PHP[/u] code: [code=php] echo 'Hello world!'; [/code] That's all folk! </code></pre> <p>The HTML output is:</p> <pre><code>This is &lt;b&gt;bold and &lt;i&gt;italic&lt;/i&gt;&lt;/b&gt;. This is some &lt;u&gt;PHP&lt;/u&gt; code: &lt;pre class="php" style="font-family:monospace;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;echo&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;'Hello world!'&lt;/span&gt;&lt;span style="color: #339933;"&gt;;&lt;/span&gt; &amp;nbsp;&lt;/pre&gt; That's all folk! </code></pre> <p>...with no p tags. So how do I add this feature?</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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