tags:

views:

46

answers:

5

Hi all,

I'm pulling content from a DB that has been sanitized using mysql_real_escape_string. Accordingly the new line characters now appear as "\n". The issue is that this content is displayed to users inside a < pre > tag so I cannot replace \n with < br/> for instance.

I suppose I could replace \n with the actual utf8 character code before inserting the result inside the < pre>.

Can somoneone assist here? Not using mysql_real_escape_string isn't really an option due to security policy.

Thanks.

A: 

I didn't tried but maybe try str_replace("\n", "[click enter here]", $string)

kasp3r
sorry but I don't understand what you're aiming at.
I think the suggestion is to press enter inside the string. This isn't necessary. See the distinction between '\n' and "\n" as mentioned in other answers.
Michael Mior
+5  A: 
echo '<pre>'.str_replace('\n', "\n", $string).'</pre>';
Mark Baker
this would work as a 'quick fix'. The root cause is the data being escaped twice
+1  A: 
str_replace("\\n","\n",$data);
R. Hill
A: 

This might help a bit:

echo('test\ntest'); shows as

test test

but echo("test\ntest"); shows as

test

test

Morgen32
echo('test\ntest'); should appear as test\ntest
Mark Baker
A: 

I'm pulling content from a DB that has been sanitized using mysql_real_escape_string. Accordingly the new line characters now appear as "\n"

If you've not done anything to the raw data pulled back from the database then the ptoblem is that it has been 'sanitized' twice when inserted.

C.

symcbean