罗安
我目前正在考虑从 table1 中拆分一长行并插入另一个 table2 中的多列,字符串值由“/”和“-”分隔。 有没有办法在出现“/”或“-”时拆分单元格值并将其插入到现有的 table2 的单独列中?
我有一个包含这样条目的表格。
要转动这个:table1
- id 值
- 1 FO910/test123/KO9200-7890/asdasd23423/...
- 2 ML45/uj890-892ht/kjsl923023/sdsds-wer3434 ..
进入此:表2
- id 值1 值2 ...
- 1 F0910 测试123
- 2 ML45 UJ890
任何帮助将不胜感激
最佳答案
尝试使用
$data= "FO910/test123/KO9200-7890/asdasd23423"
$row = preg_split("/[\/\-]/", $data);
/* example output
array(1)
(
[0] => string(5) "FO910"
[1] => string(7) "test123"
[2] => string(6) "KO9200"
[3] => string(4) "7890"
[4] => string(12) "asdasd23423"
) */
foreach($col in $row )
{
echo '<td>'.$col.'</td>';
}
关于php - Mysql-PHP如何将长字符串行分成不同的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12168456/