/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Find number in keys of an array

Hi, I have a array looks like :
Array ( [0] => ‘C:MATLAB7worktext by PHP1business_2company/1business_2company_id118txt’
[1] => ‘C:MATLAB7worktext by PHP1business_2company/1business_2company_id119txt’
[2] => ‘C:MATLAB7worktext by PHP1business_2company/1business_2company_id11txt’
……
[10] => ‘C:MATLAB7worktext by PHP1business_2company/1business_2company_id8txt’ )

I want to only get the numeric string from each key of the array and get the output as:
Array ( [0] => 71212118 [1] =>71212119 [2] =>7121211 ……
[10] =>712128)

How to do this? ?

Thank You

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@pcthugJul 14.2006 — This quick script I made should do the trick:[code=php]<?php
$array = array('C:MATLAB7worktext by PHP1business_2company/1business_2company_id118txt',
'C:MATLAB7worktext by PHP1business_2company/1business_2company_id119txt',
'C:MATLAB7worktext by PHP1business_2company/1business_2company_id11txt');

print_r($array);

// removes any characters that are not decimals
function onlyDecimals($str) {
$str = ereg_replace("[^0-9]", "", $str);
return $str;
}

print_r(array_map('onlyDecimals', $array));
?>[/code]
Should output:Array
(
[0] =&gt; C:MATLAB7worktext by PHP1business_2company/1business_2company_id118txt
[1] =&gt; C:MATLAB7worktext by PHP1business_2company/1business_2company_id119txt
[2] =&gt; C:MATLAB7worktext by PHP1business_2company/1business_2company_id11txt
)
Array
(
[0] =&gt; 71212118
[1] =&gt; 71212119
[2] =&gt; 7121211
)
Copy linkTweet thisAlerts:
@yunfannyauthorJul 15.2006 — Hi, thank you, pcthug. I tried it myself also. It works !
×

Success!

Help @yunfanny spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...