Jump to content

BBCode and new lines grrr


onlyican

Recommended Posts

hey all. It may have been dealt with. but I am ill and tired so please link or slap round the face to wake me up ;)

 

Basically, new project has a WYSIWYG style BBCode Editor (hey, bit like this here)

 

Anyway, the new Line is killing me

 

I have nl2br() but it aint doing anything

 

Example Code

//Dont say it, i know $str is a BAD variable name, but this is from a private function inside a class
$str = nl2br($str);
$regexURLPattern = '#(\[url\=(.*))(\])(.*)(\[/url\])#';
	preg_match_all($regexURLPattern, $str, $arrMatches);

	for($i = 0; $i < count($arrMatches[0]); $i++){
		$strNewLink = '<a href="'.$arrMatches[2][$i].'" target="_blank">'.$arrMatches[4][$i].'</a>';
		$str = str_replace($arrMatches[0][$i], $strNewLink, $str);

	}

 

so


[url=http://www.example.com]Text[/url]
// Outputs correctly

[url=http://www.example.com]Not
Idiot Proof[/url]
// See what I did, added a new line like an idiot would, it now breaks

 

Please help

Link to comment
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.