表现与业务逻辑分离
PHP和HTML混写,很乱啊,怎么解决?
<?php
$articles = array();
$file = './articles.json';
if (file_exists($file)) {
$tmp = file_get_contents($file);
if (!empty($tmp)) {
$articles = json_decode($tmp, true);
}
}
$d = array(); //d 是 data的意思,后续会用到
$d['articles'] = $articles;
require_once __DIR__ . '/index.html';<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-Hans" lang="zh-Hans">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>在线阅读</title>
</head>
<body>
<h1>在线阅读</h1>
<div><a href="./add_article.html">写文章</a></div>
<?php
if (!empty($d['articles'])) {
echo '<ul>';
foreach ($d['articles'] as $k=>$v) {
$id = $k + 1;
echo '<li><a href="./get_article.php?id=' . $id . '">' . $v['title'] . '</a>';
echo '<p>' . mb_substr($v['content'], 0, 100, 'UTF-8') . '……</p></li>';
}
echo '</ul>';
}
?>
</body>
</html>保存之后,在Firefox中页面怎么乱码了?

总结一下
我的技术水平
已解决的问题
待解决的问题
Last updated