What is wrong with: str_replace("", "", $content);
What is wrong with: str_replace("", "", $content);
am 10.01.2008 09:19:48 von jodleren
Hi all
I have text area, where I can edit files - but I have to correct the
returned data, for that I use
$content=str_replace('\"', '"', $content);
and
$content=str_replace('\\', '\', $content);
by some reason the latter one causes an error: syntax error,
unexpected T_VARIABLE in....
Replacing :-) it by
$content=str_replace("\\\\", "\\", $content);
and it works
what is wrong with '\\' ?
WBR
Sonnich
Re: What is wrong with: str_replace("", "", $content);
am 10.01.2008 10:44:31 von Anders
try
$content=str_replace("\\'", "'\'", $content);
// Anders
On 10 Jan, 09:19, jodleren wrote:
> Hi all
>
> I have text area, where I can edit files - but I have to correct the
> returned data, for that I use
>
> $content=str_replace('\"', '"', $content);
> and
> $content=str_replace('\\', '\', $content);
>
> by some reason the latter one causes an error: syntax error,
> unexpected T_VARIABLE in....
> Replacing :-) it by
>
> $content=str_replace("\\\\", "\\", $content);
>
> and it works
>
> what is wrong with '\\' ?
>
> WBR
> Sonnich
Re: What is wrong with: str_replace("", "", $content);
am 10.01.2008 10:55:25 von gordon
On Jan 10, 8:19 am, jodleren wrote:
> Hi all
>
> I have text area, where I can edit files - but I have to correct the
> returned data, for that I use
>
> $content=str_replace('\"', '"', $content);
> and
> $content=str_replace('\\', '\', $content);
>
> by some reason the latter one causes an error: syntax error,
> unexpected T_VARIABLE in....
> Replacing :-) it by
>
> $content=str_replace("\\\\", "\\", $content);
>
> and it works
>
> what is wrong with '\\' ?
>
> WBR
> Sonnich
It's because the backslash character is used for escaping characters
in strings, in other words telling the parser to treat the following
character as its literal value instead of the special meaning it may
have in the language. For example the ' character closes a single
quoted string, so if you want to use that character inside a string
you have to enter it as \' which basically tells the parser "Don't end
the string with this ' symbol, insert the ' character into the string
instead".
As the \ character has a sepcial meaning if you want to insert it then
you have to escape it, resulting in \\
If the intention is to remove slashes from form-submitted data (which
is what I suspect you are trying to do) then you might want to look
into using the stripslashes () function instead.
Re: What is wrong with: str_replace("", "", $content);
am 10.01.2008 11:09:04 von jodleren
On Jan 10, 11:55=A0am, Gordon wrote:
> On Jan 10, 8:19 am, jodleren wrote:
>
> If the intention is to remove slashes from form-submitted data (which
> is what I suspect you are trying to do) then you might want to look
> into using the stripslashes () function instead.- Hide quoted text -
Thanks
That was what I was looking for.