简体   繁体   中英

How to remove everything from a string except for the number and put these in an array?

How to remove everything from a string except for the number and put these in an array?

["103","109","110"]

has to be a string with just the numbers.

I am using smarty and tried this.

{assign downloadCats $aMenu.aMenuvars.downloads|ltrim:'['|rtrim:']'}

{','|explode:$downloadCats}
{var_dump($downloadCats)}

You could use regular expressions for this:

preg_match_all("/[0-9]+/", $input, $findings, PREG_SET_ORDER);
foreach ($findings as $value) {
  // do something with the value
}

For more infos or examples look here: http://php.net/manual/de/function.preg-match-all.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM