通过PHP来 获取文件内容 并且分割字符串 呈现在表格中

时间:2019-03-16
本文章向大家介绍通过PHP来 获取文件内容 并且分割字符串 呈现在表格中,主要包括通过PHP来 获取文件内容 并且分割字符串 呈现在表格中使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
<?php

$aaa = file_get_contents("names.txt");
$data = explode("\n", $aaa);
foreach ($data as $key) {
    if (!$key) continue;
    else {
        $col = explode('|', $key);
        $final[] = $col;
    }
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        table td {
            text-align: center;
        }
    </style>
</head>
<body>
<div>
    <table>
        <thead>
        <tr>
            <td>编号</td>
            <td>姓名</td>
            <td>年龄</td>
            <td>邮箱</td>
            <td>网址</td>
        </tr>
        </thead>
        <tbody>
        <?php foreach ($final as $item): ?>
        <tr>
            <?php foreach ($item as $val): ?>
                <?php $temp = trim($val); ?>
                <?php if (strpos($temp, 'http://') === 0): ?>
                    <td><a href="<?php echo strtolower($temp) ?>"><?php echo substr($temp,7) ?></a></td>
                <?php else : ?>
                    <td><?php echo $val; ?></td>
                <?php endif ?>
            <?php endforeach ?>

            <?php endforeach ?>
        </tbody>
    </table>
</div>
</body>
</html>