FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » str_replace does not like empty quotes
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: str_replace does not like empty quotes [message #186191 is a reply to message #186189] Fri, 20 June 2014 00:11 Go to previous messageGo to previous message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma:
Member
On Thursday 19 June 2014 19:33, in comp.lang.php, "richard"
<noreply(at)example(dot)com> wrote:

> $a=str_replace($a,"\","");
>
> This generates the error: Unexpected "".

Of course it does. You are trying to replace all the strings that match $a
with "\" in an empty string ("").

> http://www.php.net//manual/en/function.str-replace.php
>
> While here in the manual, they do precisely the same thing!

To quote the webpage:
# str_replace — Replace all occurrences of the search string with the
# replacement string
# Description
# mixed str_replace ( mixed $search , mixed $replace , mixed $subject
# [, int &$count ] )
#
# This function returns a string or an array with all occurrences of search
# in subject replaced with the given replace value.

Note that "search" is the first parameter, "replace" is the second,
and "subject" is the third.

So, your
str_replace($a,"\","");
will return a string or array with all occurrences of
the contents of $a
in
""
with the given
"\"
value


What you apparently want is
str_replace("\","",$a);

> <quote>
> If search and replace are arrays, then str_replace() takes a value from
> each array and uses them to search and replace on subject. If replace has
> fewer values than search, then an empty string is used for the rest of
> replacement values. If search is an array and replace is a string, then
> this replacement string is used for every value of search. The converse
> would not make sense, though.
> </quote>


--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PDO fetch with SQL server
Next Topic: Putting it all together
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun May 12 12:56:21 GMT 2024

Total time taken to generate the page: 0.05511 seconds