Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #10719
| From | Twayne <nobody@spamcop.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: str_replace & assign to a var? |
| Date | 2013-09-04 14:52 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <l07vh7$m66$1@speranza.aioe.org> (permalink) |
| References | <l07qmq$8o0$1@speranza.aioe.org> <b8pbn7Fdg6bU1@mid.individual.net> |
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`
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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