簡體   English   中英

如何從字符串中刪除除數字之外的所有內容並將它們放入數組中?

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

如何從字符串中刪除除數字之外的所有內容並將它們放入數組中?

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

必須是一個只有數字的字符串。

我正在使用 smarty 並嘗試過這個。

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

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

您可以為此使用正則表達式:

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

有關更多信息或示例,請查看此處: http : //php.net/manual/de/function.preg-match-all.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM