Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]what happens to textarea content when inserted to the db?
#1

[eluser]bobbob[/eluser]
I am having an odd problem where some outputted textarea breaks my marker code in google maps. It appears that using nl2br() doesn't remove the \n properly
Code:
var marker = createMarker(point,"<div style=\"width:400px height:450px\">&lt;?php echo $loc; ?&gt;<br>&lt;?php echo nl2br($description); ?&gt;<br></div>");

I have plyed with htmlentities and str_replace with no luck
#2

[eluser]simshaun[/eluser]
Is the data coming from a database? If so, have you done anything to the data before you inserted it into the db?
#3

[eluser]bobbob[/eluser]
I was doing an xxs_clean but i bypassed that to see hwhat happened and the same ting happens.
firebug shows:
unterminated string literal

var marker = createMarker(point,"<...:400px height:450px\">ddd<br>dddd<br />\n
#4

[eluser]simshaun[/eluser]
Is your data delimited by \r\n or just \n? I could be wrong, but I believe nl2br only converts \r\n.
#5

[eluser]drewbee[/eluser]
Try this:

Code:
var marker = createMarker(point,'<div style="width:400px height:450px">&lt;?php echo $loc; ?&gt;<br>&lt;?php echo str_replace("'", "\'",nl2br($description)); ?&gt;<br></div>');
#6

[eluser]bobbob[/eluser]
Tried the last example and no luck with str_replace()

Also I am on a mac. I think that does alter the \n
#7

[eluser]bobbob[/eluser]
Solved it with this function from someone else:

Code:
&lt;?php
function removeLineBreaks($input)
{
   $input     = preg_replace('/(?<!\n)\n(?!\n)/', "<br />", $input);
   $output     = str_replace("\r", "", $input);
  
   return $output;
}
?&gt;

&lt;?php echo removeLineBreaks($description); ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB