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 #186192 is a reply to message #186191] Fri, 20 June 2014 00:55 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 6/19/2014 8:11 PM, Lew Pitcher wrote:
> 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,

Not quite. Hint: think escape character...

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
[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: Thu Nov 21 21:31:18 GMT 2024

Total time taken to generate the page: 0.05320 seconds