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

Home » Imported messages » comp.lang.php » str_replace & assign to a var?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: str_replace & assign to a var? [message #182761 is a reply to message #182760] Thu, 05 September 2013 14:34 Go to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma:
Senior Member
On 2013-09-05 4:48 AM, Curtis Dyer wrote:
> "J.O. Aho" <user(at)example(dot)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`
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: calling a value into another php script...
Next Topic: Strange url session behaviour after upgrade to 4.3
Goto Forum:
  

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

Current Time: Sun Dec 01 01:40:22 GMT 2024

Total time taken to generate the page: 0.04667 seconds