joomla
asked on
issue with \n\r and nl2br
I'm passing a variable in my URL
index.php?p=this\r\ntext
using $_GET[var] I'm getting this\\r\\ntext
why is \r\n being modified to \\r\\n
nl2br() won't work in my variable
replace_sub("\\r\\n","<br/ >", $var) doesn't work either ?
can you help?
index.php?p=this\r\ntext
using $_GET[var] I'm getting this\\r\\ntext
why is \r\n being modified to \\r\\n
nl2br() won't work in my variable
replace_sub("\\r\\n","<br/
can you help?
ASKER
this is how far I seem to get
index.php?p=separate\r\nli
$var=$_GET[var];
what $var gets is "\\r\\n" (don't understand why the change. as I inputed "\r\n")
$unwanted=array("\r","\n",
$wanted="<br/>";
$var= str_replace($unwanted,$wan
results in $var = separate<br/>lines
when I put this in the text area it shows
separate<br/>lines
I wanted it to show
separate
lines
thanks for any help
If you want it on separate lines in a text area, you don't need to use <br/> - text areas pay attention to line breaks. Just change $wanted = "\r\n"; and you should see what you're looking for.
The problem is that by default, PHP tries to automatically escape special characters that are entered via the query string. It's a security thing, which you can turn off, but that's not recommmended. It's better to simply fix any specific cases like this.
The problem is that by default, PHP tries to automatically escape special characters that are entered via the query string. It's a security thing, which you can turn off, but that's not recommmended. It's better to simply fix any specific cases like this.
ASKER
Hi gr8gonzo:
thanks for feedback
unfortunately your suggested didn't work
regards
M
thanks for feedback
unfortunately your suggested didn't work
regards
M
What does your code look like right now?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is simple codes and should be working ...
NOTICE the way I use single quotes and double quotes in str_replace
Regards...
NOTICE the way I use single quotes and double quotes in str_replace
$var = $_GET['p'];
$var = stripslashes($var);
// Turning \r\n to breakspace in textarea
echo '<textarea>'.str_replace('\r\n', "\r\n", $var).'</textarea>';
Regards...
And here's for the learning purposes (for those who wonder) :-)
<?php
// \r\n on single quotes
$var1 = 'NO break \r\n space';
// \r\n on double quotes
$var2 = "YES break \r\n space";
// echo $var1 in TEXTAREA
echo 'Var#1: <textarea>'.$var1.'</textarea>';
// echo $var2 in TEXTAREA
echo 'Var#2: <textarea>'.$var2.'</textarea>';
?>
$var = str_replace("\\\\r\\\\n","