简体   繁体   English

Mysql-PHP如何将长字符串行分成不同的列?

[英]Mysql-PHP how to separate long string row into different columns?

Roan 罗恩

I am currently looking into spliting a long row,from table1 and insert in multiple columns in another table2, the string the values are separated by a "/" and "-". 我目前正在研究从table1拆分一长行,并在另一个table2的多列中插入,值的字符串由“ /”和“-”分隔。 is there a way to split a cell values at the occurrence of the "/" or "-" and insert in to the existing table2 in their separate columns? 有没有一种方法可以在出现“ /”或“-”时拆分单元格值,并将其插入到现有table2的单独列中?

I've a table with entries like this. 我的桌子上有这样的条目。

To turn this: table1 要解决这个问题:table1

    id value id值
    1 FO910/test123/KO9200-7890/asdasd23423/ ... 1 FO910 / test123 / KO9200-7890 / asdasd23423 / ...
    2 ML45/uj890-892ht/kjsl923023/sdsds-wer3434 .. 2 ML45 / uj890-892ht / kjsl923023 / sdsds-wer3434 ..

into this: table2 到此:table2

    id value1 value2 ... id值1值2 ...
    1 F0910 test123 1个F0910 test123
    2 ML45 UJ890 2 ML45 UJ890

any help will be appreciated greatly 任何帮助将不胜感激

Try using 尝试使用

$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>';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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