iT邦幫忙

0

<解決>split問題請教

  • 分享至 

  • xImage

若是a=21,22,23
要切就是split(,)
那請教若是a=0.262 0.365 0.645
要如何實現在0.之前切?

目前是用空白切,但是想知道有沒有方法在0.前切

$textarea = $_POST["abc"];
$aa =explode("\n", str_replace("\r\n", "\n", $textarea));
archer9080 iT邦研究生 4 級 ‧ 2021-11-10 18:20:13 檢舉
如果結果只是單純要0.xxx
既然用了explode,以0.作為切割依據再拼接應該也可以(?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
Han
iT邦研究生 1 級 ‧ 2021-11-09 18:20:11
最佳解答

也許你可以考慮用正規把小數點的字串抓出來,不過也有 preg-split 這東西啦..
只是規則可能比較不好寫
https://www.php.net/manual/en/function.preg-split.php

<?php
$a = '0.123 0.456 0.789';

preg_match_all('/0\.\d+/', $a, $matches);

var_dump($matches);

我要發表回答

立即登入回答