Escape characters in php
Moderator: General Moderators
Escape characters in php
In many languages '\n' means the line break character
how to write it in php?
how to write it in php?
Re: Escape characters in php
The same way - just use double quotes, not single ones.
Code: Select all
echo "A new line character \n is put here";There are 10 types of people in this world, those who understand binary and those who don't
Re: Escape characters in php
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";
Re: Escape characters in php
There are 10 types of people in this world, those who understand binary and those who don't
Re: Escape characters in php
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";
Lastly, this does n't append as epected. What's wrong?
$aaa = $aaa . "<br />";
Re: Escape characters in php
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:
Code: Select all
$aaa .= "<br />";Please, use [ php ] BB tags instead of [ code ] BB tags when posting PHP code.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Escape characters in php
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.
Re: Escape characters in php
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:
If I replace "\n" with say "k" no problem; get an exception when it with "\n"
Thanks for any ideas why ...
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;
}
Thanks for any ideas why ...
Re: Escape characters in php
I have been trying out
$aaa = nl2br($aaa);
but i get a php error with this (this line is inside a function).
nl2br($aaa);
is ok, though I obviously dont get the result.
How to do the assignment properly?
However, to be honest I'd prefer to get
str_replace("\n", "x", $aaa);
working.
$aaa = nl2br($aaa);
but i get a php error with this (this line is inside a function).
nl2br($aaa);
is ok, though I obviously dont get the result.
How to do the assignment properly?
However, to be honest I'd prefer to get
str_replace("\n", "x", $aaa);
working.
Re: Escape characters in php
Ah, I think the problem might be this:
that i have to return an Object rather than a String.
Does that make sense? How to change my object into a string for the relacements, then the string back into an oject? Perhaps the object is an array of strings?
I always get an Object Required error from php. Is $aaa not proper object?
that i have to return an Object rather than a String.
Does that make sense? How to change my object into a string for the relacements, then the string back into an oject? Perhaps the object is an array of strings?
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;
}
Re: Escape characters in php
My best guess at what it should be is
But same Object Expected error 
Code: Select all
function onGetContent( $editor ) {
$aaa[] = "document.getElementById( '$editor' ).value;\n";
$order=array("\n");
$replace = '#';
$newaaa[] = str_replace($order, $replace, $aaa);
return $newaaa;
}
Re: Escape characters in php
If I write this:
$order=array("\n");
I get a '; expected' error - why is that?
$order=array("\n");
I get a '; expected' error - why is that?
Re: Escape characters in php
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?
There are 10 types of people in this world, those who understand binary and those who don't
Re: Escape characters in php
$aaa = nl2br($aaa);
Gives a syntax error
why is that ?
Gives a syntax error
why is that ?
Re: Escape characters in php
'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?
The function that calls it expects an array.