把下面的内容序列化 然后转数组 能每一行循环输出 最后要建一个表格

胖胖 发布于 2015/08/12 18:22
阅读 223
收藏 0
PHP
aaaaaaaaaaaaaaa|ffffffffffffffff
aaaaaaaaaaaaaaa|ffffffffffffffff|eeeeeeeeeeeeeeee|
aaaaaaaaaaaaaaa|ffffffffffffffff|eeeeeeeeeeeeeeee|rrrrrrr|tttttttttttt
加载中
0
leo108
leo108

explode不够用?

胖胖
胖胖
好多行啊,每一行长度还不一样,最后生成表格的时候长度不一样的为空啊,不会弄,能写个例子吗。
0
Jceee
Jceee

example:

$str = 'aaaaaaaaaaaaaaa|ffffffffffffffff
aaaaaaaaaaaaaaa|ffffffffffffffff|eeeeeeeeeeeeeeee|
aaaaaaaaaaaaaaa|ffffffffffffffff|eeeeeeeeeeeeeeee|rrrrrrr|tttttttttttt';


$array = explode("\n", $str);


foreach ($array as &$value) {
    $value = explode('|', $value);
}
unset($value);


$tableString = '<table>';
foreach ($array as $_values) {
    $tableString .= '<tr>';
    foreach ($_values as $_item) {
        $tableString .= '<td>';
        $tableString .= $_item;
        $tableString .= '</td>';
    }
    $tableString .= '</tr>';
}
$tableString .= '</table>';
echo $tableString;

0
技术揣摩
技术揣摩

str_replace('|',',',$str); 

然后CSV输出

返回顶部
顶部