Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #10721

Re: str_replace & assign to a var?

From Twayne <nobody@spamcop.net>
Newsgroups comp.lang.php
Subject Re: str_replace & assign to a var?
Date 2013-09-05 10:34 -0400
Organization Aioe.org NNTP Server
Message-ID <l0a4p3$2iv$1@speranza.aioe.org> (permalink)
References <l07qmq$8o0$1@speranza.aioe.org> <b8pbn7Fdg6bU1@mid.individual.net> <l09ggg$30v$1@dont-email.me>

Show all headers | View raw


On 2013-09-05 4:48 AM, Curtis Dyer wrote:
> "J.O. Aho" <user@example.net> wrote:
>
>> On 04/09/13 19:29, Twayne wrote:
>>> Hi Guys & Gals,
>>>
...
>>> I have the following canned code:
>>> ------------
>>> $arr = array("blue","red","green","yellow");
>>> print_r(str_replace("red","pink",$arr,$i));
>>> echo "<br>" . "Replacements: $i";
>>> -----------
>>>
>>> All I want to do is change "red" to "pink" IN the array or a
>>> new array. How do I do that?
...

>>
>> The filterNumbers do the actual work (you can make it a lot more
>> advanced, depending on your needs).
>
> In this case, however, it seems unnecessary. The `str_replace'
> function will already return the altered array when the `subject'
> parameter is an array. So, in the OP's code snippet above, we need
> to change the `str_replace' line:
>
>    <?php
>    $i = 0;
>
>    /* ... */
>
>    $arr = str_replace('red', 'pink', $arr, $i);
>    print_r($arr);
>    ?>
>
>
> <snip>
>

Hmm, I've read the Manual, w3schools, Tizag and several others but never 
did pick up on 'subject' being my issue.

Thanks much,

Twayne`

Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

str_replace & assign to a var? Twayne <nobody@spamcop.net> - 2013-09-04 13:29 -0400
  Re: str_replace & assign to a var? NEVER MIND Twayne <nobody@spamcop.net> - 2013-09-04 14:00 -0400
  Re: str_replace & assign to a var? "J.O. Aho" <user@example.net> - 2013-09-04 20:16 +0200
    Re: str_replace & assign to a var? Twayne <nobody@spamcop.net> - 2013-09-04 14:52 -0400
    Re: str_replace & assign to a var? Curtis Dyer <dyer85@gmail.com> - 2013-09-05 08:48 +0000
      Re: str_replace & assign to a var? Twayne <nobody@spamcop.net> - 2013-09-05 10:34 -0400

csiph-web