Jump to content

Recommended Posts

With my current script it seems to only work if i have something like

echo "
[center]word[/center]
";

but not when it is like

echo "
[center]
word
[/center]
";

(with out any break lines, just /r/n)

 

the code for center is

$code = preg_replace("/\[center\](.*?)\[\/center\]/","<center>\\1</center>",$code);

 

Link to comment
https://forums.phpfreaks.com/topic/141265-bbcode-problems/
Share on other sites

Thanks, but i have half solved it

 

I made two tests like so

 

$mesg = secure("

[center] test [/center]


[scroll]test[/scroll]
");  //does htmlentities and trim, i need to change it 
$mesg = bbcode($mesg); 
echo nl2br($mesg);
/*^prints, 
            test
\r\n\r\n
\r\ndoes it work like this?\r\n
*/

That has test centered and the scroll working but nl2br stops working :S

 

Edit: the function

function secure()
{
    $arg_count = func_num_args();
	$arg_list = func_get_args();

	for ($i = 0; $i < $arg_count; $i++) 
	{
		$un_secure = $arg_list[$i];
		$un_secure = htmlentities($un_secure);
		$un_secure = trim($un_secure);
		if(@mysql_ping())
			$un_secure = mysql_real_escape_string($un_secure);
		if($arg_count == 1)
			$secured = $un_secure;
		else
			$secured[] = $un_secure;
	}	
	return $secured;
}

 

Link to comment
https://forums.phpfreaks.com/topic/141265-bbcode-problems/#findComment-739398
Share on other sites

Ok, so here are my updated functions

<?php
## Function: BBCode ##
function bbcode($code)
{
	//colors, links, images,email,quotes,block
	//marquee
	$code = preg_replace("/\[scroll\](.*?)\[\/scroll\]/","<marquee>\\1</marquee>",$code);
	//user
	//$code = preg_replace("/\[user\](.*?)\[\/user\]/","<a href=''>\\1</a>",$code);
	//strong
	$code = preg_replace("/\[strong\](.*?)\[\/strong\]/","<strong>\\1</strong>",$code);
	//definition list
	$code = preg_replace("/\[dlist\](.*?)\[\/dlist\]/","<dl>\\1</dl>",$code);
	   //term
	   $code = preg_replace("/\[term\](.*?)\[\/term\]/","<dt>\\1</dt>",$code);
	   //definition
	   $code = preg_replace("/\[def\](.*?)\[\/def\]/","<dd>\\1</dd>",$code);
	   
	//unorganized list
	$code = preg_replace("/\[ulist\](.*?)\[\/ulist\]/","<ul>\\1</ul>",$code);
	//organized list
	$code = preg_replace("/\[olist\](.*?)\[\/olist\]/","<ol>\\1</ol>",$code);
	//list item
	$code = preg_replace("/\[item\](.*?)\[\/item\]/","<li>\\1</li>",$code);
	//sub
	$code = preg_replace("/\[sup\](.*?)\[\/sup\]/","<sup>\\1</sup>",$code);
	//super
	$code = preg_replace("/\[sub\](.*?)\[\/sub\]/","<sub>\\1</sub>",$code);
	//pre
	$code = preg_replace("/\[pre\](.*?)\[\/pre\]/","<pre>\\1</pre>",$code);
	//emphazied
	$code = preg_replace("/\[em\](.*?)\[\/em\]/","<em>\\1</em>",$code);
	//italic
	$code = preg_replace("/\[i\](.*?)\[\/i\]/","<i>\\1</i>",$code);
	//strikethrough
	$code = preg_replace("/\[s\](.*?)\[\/s\]/","<del>\\1</del>",$code);
	//bold
	$code = preg_replace("/\[b\](.*?)\[\/b\]/","<b>\\1</b>",$code);
	$code = preg_replace("/\<b\>(.*?)\<\/b\>/","<b>\\1</b>",$code);
	//center
	$code = preg_replace("/\[center\](.*?)\[\/center\]/","<center>\\1</center>",$code);

	return $code;
}

## Function: Secure ##
	//Custom function to secure limitless(within reason if you want to keep speed up) variables, now supports arrays, single dimension arrays only!!
	function secure()
	{
	    $arg_count = func_num_args();//Get the number of submitted arguments
		$arg_list = func_get_args();//Store the arguments in a array
		for ($i = 0; $i < $arg_count; $i++) //Loop through all the arguments
		{
			$un_secure = $arg_list[$i];//Store the current argument in a string
			if(is_array($un_secure))//Check if the argument is an array
			{
				foreach($un_secure as $securing)//Loop through the argument array
				{
					$securing = htmlentities($securing);//Convert special chars, such as ' " @ etc., into HTML entities

					$securing = trim($securing);//Remove any whitespace either side of the var

					$securing = nl2br($securing);//Convert all /n to <br />, needed for displaying multiple lined vars

					$securing = bbcode($securing);//Apply bbcode to the var

					$un_secured[] = $securing;
				}
			}
			else
			{
				$un_secured = htmlentities($un_secure);//Convert special chars, such as ' " @ etc., into HTML entities

				$un_secured = trim($un_secured);//Remove any whitespace either side of the var

				$un_secured = nl2br($un_secured);//Convert all /n to <br />, needed for displaying multiple lined vars

				$un_secured = bbcode($un_secured);//Apply bbcode to the var
			}
				if($arg_count == 1)//If their is only one argument store it in a var
					$secured = $un_secured;
				else //If there are multiple arguments store it in an array so it can be used again in the loop
					$secured[] = $un_secured;
		}	
		return $secured;//Return the secured argument(s)
	}

?>

 

And still when i do

 

echo secure("[b]test[/b]");//this works
//but
$str = "
[b]
test
[/b]
";
echo secure($str);//this doesn't

 

Also for that secure function i have, anyone know how i can make it support limitless arrays?

 

Would that be the best way, below?

	function secure()
	{
	    $arg_count = func_num_args();//Get the number of submitted arguments
		$arg_list = func_get_args();//Store the arguments in a array
		for ($i = 0; $i < $arg_count; $i++) //Loop through all the arguments
		{
			$un_secure = $arg_list[$i];//Store the current argument in a string
			if(is_array($un_secure))//Check if the argument is an array
			{
				foreach($un_secure as $securing)//Loop through the argument array
				{
					$securing = htmlentities($securing);//Convert special chars, such as ' " @ etc., into HTML entities

					$securing = trim($securing);//Remove any whitespace either side of the var

					$securing = nl2br($securing);//Convert all /n to <br />, needed for displaying multiple lined vars

					$securing = bbcode($securing);//Apply bbcode to the var
					if(is_array($securing)){$un_secured[] = secure($securing)}
                                                else
					   $un_secured[] = $securing;
				}
			}
			else
			{
				$un_secured = htmlentities($un_secure);//Convert special chars, such as ' " @ etc., into HTML entities

				$un_secured = trim($un_secured);//Remove any whitespace either side of the var

				$un_secured = nl2br($un_secured);//Convert all /n to <br />, needed for displaying multiple lined vars

				$un_secured = bbcode($un_secured);//Apply bbcode to the var
			}
				if($arg_count == 1)//If their is only one argument store it in a var
					$secured = $un_secured;
				else //If there are multiple arguments store it in an array so it can be used again in the loop
					$secured[] = $un_secured;
		}	
		return $secured;//Return the secured argument(s)
	}

Link to comment
https://forums.phpfreaks.com/topic/141265-bbcode-problems/#findComment-745490
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.