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 #182759 is a reply to message #182758] Wed, 04 September 2013 18:52 Go to previous messageGo to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma:
Senior Member
On 2013-09-04 2:16 PM, J.O. Aho wrote:
> On 04/09/13 19:29, Twayne wrote:
>> Hi Guys & Gals,
>>
....
>>
>> 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.
>>
>
> Here is an example how to make it neatly and this can be made quite
> dynamic by chancing the function to use for remapping the cell content:
>
> <?php
>
> function filterNumbers($str) {
> return str_replace('-', '', $str);
> }
>
> $oldArray=array('1234-1234', '2345-2345', 'ABCD.FGHI', '3456.3456',
> '-0987-0987');
>
> $newArray=array_map('filterNumbers', $oldArray);
>
> var_dump($newArray);
>
> ?>
>
> The filterNumbers do the actual work (you can make it a lot more
> advanced, depending on your needs).
>
> then you input the remapping function and the original array as
> arguments and you then get a modified array back.
>
> If you want to remove items in an array, then use the array_filter(),
> the argument order is different and the function needs to return true or
> false.
>

I'm not ignoring your advice; just thinking & doing some research; those
are new areas for me a and they look very useful. THANKS!

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:33:08 GMT 2024

Total time taken to generate the page: 0.02977 seconds