How do i use this php parser with mysql?

how do i use this parser with mysqli?
coz i wanna use it with my chat System that i have
Yes i know theres an exmpale but that does not help me at all

<?php

/** 
* A simple DisqusShortCode Parser function
*
* @author shoaiyb sysa
* @see https://snowdev.ml/
**/

//Shortcode Parser function

function disqusParser($text) {
	
	// NOTE : I had to update this sample code with below line to prevent obvious attacks as pointed out by many users.
	// Always ensure that user inputs are scanned and filtered properly.
	$text  = htmlspecialchars($text, ENT_QUOTES, $charset);

	// BBcode array
	$find = array(
    '~\[disqus\]~s',
    '~\[disqus\][/disqus\]~s'
 /* '~\[b\](.*?)\[/b\]~s',
		'~\[i\](.*?)\[/i\]~s',
		'~\[u\](.*?)\[/u\]~s',
		'~\[quote\](.*?)\[/quote\]~s',
		'~\[size=(.*?)\](.*?)\[/size\]~s',
		'~\[color=(.*?)\](.*?)\[/color\]~s',
		'~\[url\]((?:ftp|https?)://.*?)\[/url\]~s',
		'~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s' */
	);

	// HTML tags to replace Shortcodes
	$replace = array(
    '$?',
    '$?'
 /* '<b>$1</b>',
		'<i>$1</i>',
		'<span style="text-decoration:underline;">$1</span>',
		'<pre>$1</'.'pre>',
		'<span style="font-size:$1px;">$2</span>',
		'<span style="color:$1;">$2</span>',
		'<a href="$1">$1</a>',
		'<img src="$1" alt="" />' */
	);

	// Replacing the BBcodes with corresponding HTML tags
	return preg_replace($find,$replace,$text);
}

// How to use the above function:

$shorttext = "This is [b]bold[/b] and this is [u]underlined[/u] and this is in [i]italics[/i] with a [color=red] red color[/color]";
$htmltext = disqusParser($shorttext);
echo $htmltext;

?>```

I would think you would store the raw text in the database, then call the function on the text on output to your page.

echo disqusParser($dbResult['text']);

Assuming $dbResult is an array fetched from your database, this will output parsed text to the page.

1 Like

Depends on if you ever want to have people edit the text again. If not, parsing and storing the result is faster and a bit simpler.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.