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
https://forums.phpfreaks.com/topic/229472-bbcode-and-new-lines-grrr/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.