Jump to content

Recommended Posts

Not sure how this is happening, so if you could tell me which function is missiong/or which is one i am using is causing it ... could you point it out.

 

 

My input for a paragraph has:

<?php
$NewMessage = mysql_real_escape_string(stripslashes($_POST['post_box']));
?>

 

 

Then output is:

<?php
//grab data from field

$Output = ucfirst(nl2br(strip_tags($Message)));
			$Message = BBCode($Output);
			echo $Message;
?>

 

Say i had:

 

Hello there

 

Hello there

 

 

As an input it  then echo's on my forum as:

 

Hello there<br   /> <br    />Hello there

 

These <br    /> should not show...and should act as an actual new line.

Thanks in advanced.

Link to comment
https://forums.phpfreaks.com/topic/116871-solved-ltbrgt-being-echod-from-input/
Share on other sites

I'm not 100% sure on what you're asking, but the <br> tags are being placed in the output by the nl2br() function.  It quite literally means transform any newlines (nl) into (2) line break tags (br).

 

Hmm, yeh but naturally that is so the format of the output remains the same as in the input...hwo ever the format is slow because rather than echo'in the break lines and actually creating a new line, it is showing the break line as a string... which means the format is then lost.

Could it be something in the BBCode function? I tried:

 

$Message = "Hello there\n\nHello there";
$Output = ucfirst(nl2br(strip_tags($Message)));
echo $Output;
?>

 

And it seemed to work fine so it's probably the BBCode function. Try getting rid of mysql_real_escape_string (temporarily) and see if that makes a difference - I'm not hopeful about that one though. I'd put my money on BBCode.

Well this is my BBCode:

 


<?php
//bb code fucntion
function BBCode($BB){
				$BBCode = array("&" => "&",
					"<" => "<",
					">" => ">",
					"[b]" => "<b>",
					"[/b]" => "</b>",
					"[i]" => "<i>",
					"[/i]" => "</i>",
					"[u]" => "<u>",
					"[/u]" => "</u>",
				$Message = str_replace(array_keys($BBCode), array_values($BBCode), $BB);
			return $Message;
								}
?>

Yep, that's it. It's replacing < with < and > with > which is messing with your HTML. You could change BBCode to:

 

<?php
//bb code fucntion
function BBCode($BB){
				$BBCode = array("&" => "&",
					"[b]" => "<b>",
					"[/b]" => "</b>",
					"[i]" => "<i>",
					"[/i]" => "</i>",
					"[u]" => "<u>",
					"[/u]" => "</u>",
				$Message = str_replace(array_keys($BBCode), array_values($BBCode), $BB);
			return $Message;
								}
?>

 

And that should fix things up.

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.