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
str_replace & assign to a var? [message #182755] Wed, 04 September 2013 17:29 Go to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma:
Senior Member
Hi Guys & Gals,

If this is a dumb question I apologize but I'm stuck. Yes, I'm
essentially a newbie to many things yet in PHP.

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?


In other words, I want to change the original array to have "pink" in it
instead of "red".

My actual goal is to take a var of "-1111-111-111" to "1111111111" and
remove the dashes. The appearance of the dashes is essentially random
but there will only be 3 of them max or even none.

Caveat: the dashes can occur almost anywhere; the var could be, for
example, -1-1-1" , 111, 999, 99-9, 9-9, etc. on up to all 9's. and so on.

I can count the dashes, see the dashes in one string and all that, but I
cannot modify seem to remove the dashes from the orginal var in order to
create a var without any dashes.
If I can get the digits-only into a new var then I can perform the
analysis I wish to on those documents.
I'd also like to avoid using regex.

TIA,

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: Sat Nov 30 23:47:36 GMT 2024

Total time taken to generate the page: 0.04750 seconds