Escape characters in php
Posted: Wed Jul 29, 2009 6:42 am
In many languages '\n' means the line break character
how to write it in php?
how to write it in php?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
echo "A new line character \n is put here";double quotes in str_replace("\n","<br>", $a) too ?VladSun wrote:The same way - just use double quotes, not single ones.Code: Select all
echo "A new line character \n is put here";
It works! ThanksVladSun wrote:The same way - just use double quotes, not single ones.Code: Select all
echo "A new line character \n is put here";
Nothing wrong. I don't know what "doesn't append as expected" meanskinabaloo wrote:Lastly, this does n't append as epected. What's wrong?
$aaa = $aaa . "<br />";
Code: Select all
$aaa .= "<br />";Ok, Thanks.VladSun wrote:Nothing wrong. I don't know what "doesn't append as expected" meanskinabaloo wrote:Lastly, this does n't append as epected. What's wrong?
$aaa = $aaa . "<br />";
Post more code, please.
Also, you may use a short form for this one:
PS:Code: Select all
$aaa .= "<br />";
Please, use [ php ] BB tags instead of [ code ] BB tags when posting PHP code.
Code: Select all
function onGetContent( $editor ) {
$aaa = "document.getElementById( '$editor' ).value;\n";
$aaa = str_replace("\n", "x", $aaa);
return $aaa;
}
Code: Select all
function onGetContent( $editor ) {
$aaa = "document.getElementById( '$editor' ).value;\n";
$aaa = str_replace("\n", '#', $aaa);
//or something like this required?
$order=array("\n");
$replace = '#';
$newaaa[] = str_replace($order, $replace, $aaa);
$aaa='';
foreach ($newaaa as $result) {
//if (trim($result))
{
$aaa .= $result;
}
}
return $aaa;
}
Code: Select all
function onGetContent( $editor ) {
$aaa[] = "document.getElementById( '$editor' ).value;\n";
$order=array("\n");
$replace = '#';
$newaaa[] = str_replace($order, $replace, $aaa);
return $newaaa;
}
Using this exact function (please, show its usage also), please tell:kinabaloo wrote:The thing is, the str_replace with double quotes only works in some places. I think that when inside a function is when it doesn't work.
In this case it is does not:Code: Select all
function onGetContent( $editor ) { $aaa = "document.getElementById( '$editor' ).value;\n"; $aaa = str_replace("\n", "x", $aaa); return $aaa; }
If I replace "\n" with say "k" no problem; get an exception when it with "\n"
Thanks for any ideas why ...
'Object Expected'VladSun wrote:Using this exact function (please, show its usage also), please tell:kinabaloo wrote:The thing is, the str_replace with double quotes only works in some places. I think that when inside a function is when it doesn't work.
In this case it is does not:Code: Select all
function onGetContent( $editor ) { $aaa = "document.getElementById( '$editor' ).value;\n"; $aaa = str_replace("\n", "x", $aaa); return $aaa; }
If I replace "\n" with say "k" no problem; get an exception when it with "\n"
Thanks for any ideas why ...
What does the Excpetion say? What is the error message?