~写html标签的好方法。
$body = [['h1'=>'Your LangShiID:'],['br'=>''],['h2'=>file_get_contents('http://composer.subnet.arily.tk/api/wolf')]];
$html = new htmltagger();
html->setBody($body)->prn();
这是0.0.2版本下的数组。 0.0.3版本,我们将它分开。
$h1 = ['h1'=>'Your LangShiID:'];
$br = ['br'=>'']; // empty string to output <**> and NULL to output <** />
$h2 = ['h2'=>file_get_contents('http://composer.subnet.arily.tk/api/wolf')];
$html = new htmltagger();
$html->setBody($h1,$br,$h2)->prn();
<body>
<h1>Your LangShiID:</h1>
<br>
<h2>kAthcirnoAm</h2>
</body>
同时, 我们先打印出<head> 即使我们还没准备好 <body> ,这样浏览器可以先加载JS和css而不用等我们打印出 <body>. 有立杆见影的速度提升效果,因为我们可能有个挺大的 <body>.
$body=[
[
'h1'=>[
'__in' =>'wowHeading'
],
//...
]
]
can like:
$body=[
[
'h1'=>'wowHeading'
//...
]
]
在你的php脚本中包含 './class.php'
一个写html标签的 好 方 法 ,而且会让你写的html 标签特别格式化。 如果你想的话,还可以存储到redis缓存中。
你可以看看example.php 特别 TMD 简单。
<?php #当然你需要这个
$head = [
/* 你需要把需要的css放进 'css' 数组中,
* 之后它会把css放进 <head>(这里)</head>
* 特简单吧?
*/
'css'=>
[
'//resource.arily.moe/resource.main/style/LL.css',
'//resource.arily.moe/resource.main/style/top.css'
],
'script' =>
[
// 这对于你可能会比较难,因为每一条JS需要一个单独的数组来告诉他这个脚本的类型
// 不过 他只是复制你的值到 <script type="(这里)" src=""></script>
// 啊,我忘了location,它的值会被放到 ^-这。
[
'type'=>'text/javascript',
'location'=>'//resource.arily.moe/Chart.js'
]
]
/*...*/
];
$body =
# body会比较难,因为你需要把所有内容放进这个数组的一个数组。
# 像是 array(array('h1'=>. 。这是因为像我们写html标签,经常会用到一堆同名的标签,
// 但是php不会允许我们有重名的键值指向不同的值。
# 同时要时刻提醒自己,你需要严格的告诉tagger你的标签中包括什么。
##
### 像是 'h1'=>array('id'=>'',
## 标签中的内容需要写在 '__in' 里面 ,
# 'h1'=>array('id'=>'','__in' =>,
// 在 '__in' 里的内容可以是数组,而且这些数组包括在它内部的标签。
#/ like 'div'=>array('id'=>'','__in' =>array('h1'=>...
//
#// 在新版,如果你只想要 '__in' ,不要别的任何参数,
##/ 你可以简单写成 'h1'=>'wowHeading';
#/#
/**
*/
[
[
'h1'=>'YES! easy html tagger using php!' //<- 新版本中这不是错误。如果不是新版你需要写成:
//this v
'h1'=>[
'__in' =>'YES! easy html tagger using php!(It\'s that f()king easy?????????'
],
'div'=>[
'id'=>'hi_i_am_div',
'__in' =>[
'h2'=>[
'id'=>'heading_2_inside_a_div!',
'__in' =>'I\'m h2 inside the fatty div '.str_repeat('that in a array ',5).'.'
]
]
]
]
];
这样你会得到下面这个html标签的输出:
<html>
<head>
<link rel="stylesheet" type="text/css" href="//resource.arily.moe/resource.main/style/LL.css">
<link rel="stylesheet" type="text/css" href="//resource.arily.moe/resource.main/style/top.css">
<script type="text/javascript" src="//resource.arily.moe/Chart.js"></script>
</head>
PHP Notice: Undefined offset: 0 in /home/webapp/info/easyhtml/class.php on line 245 (this won't happen with new code.)
<body>
<h1>YES! easy html tagger using php!(It's that f()king easy?????????</h1>
<div id="hi_i_am_div">
<h2 id="heading_2_inside_a_div!">I'm h2 inside the fatty div that in a array that in a array that in a array that in a array that in a array .</h2>
</div>
</body>
</html>
简单~ 在 phpEZhtmltagger 里 所有的 '__in'都可以包括不止一个标签。
你这次要创建2个div在一个div里
就是 <div id="main"> <div class="sub"> </div> <div class="sub"> </div> </div>.
为了创建2个标签在div中,你需要分别把他们放进彼此独立的(??)中,
对,数组。
$body =
[
[
'h1'=>[
'__in' =>'YES! easy html tagger using php!(It\'s that f()king easy?????????'
],
'div'=>[
'id'=>'hi_i_am_div',
'__in' =>
[
[
'div'=>[
'id'=>'div_inside_a_div!',
'__in' =>'I\'m div inside the fatty div '.str_repeat('that in a array ',6).'.'
]
],
[
'div'=>[
'id'=>'div_inside_a_div_num_2!',
'__in' =>'I\'m another div inside the fatty div '.str_repeat('that in a array ',6).'.'
]
]
]
]
]
];
这个会输出:
<html>
<head>
<link rel="stylesheet" type="text/css" href="//resource.arily.moe/resource.main/style/LL.css">
<link rel="stylesheet" type="text/css" href="//resource.arily.moe/resource.main/style/top.css">
<script type="text/javascript" src="//resource.arily.moe/Chart.js"></script>
</head>
<body>
<h1>YES! easy html tagger using php!(It's that f()king easy?????????</h1>
<div id="hi_i_am_div">
<div id="div_inside_a_div!">I'm div inside the fatty div that in a array that in a array that in a array that in a array that in a array that in a array .</div>
<div id="div_inside_a_div_num_2!">I'm another div inside the fatty div that in a array that in a array that in a array that in a array that in a array that in a array .</div>
</div>
</body>
</html>
因为这涉及多维数组,所以你最好仔细检查。我说的不是那种2 3维,我的例子中仅仅导航栏就用了18维。
魔法时间:
include './class.php';
$html = new htmltagger();
$html->setHead($head);
$html->setBody($body);
$html->prn();
完了。
你有俩办法。 首先你可以直接写进数组:
$head = array();
$head['title'] = 'wowTitle';
<head>
<title>wowTitle</title>
</head>
而且你可以用'setTitle'方法。 我推荐你这么干,因为你想在一堆多维数组里找到那个 'title'简直难炸了。 你可以这么做:
$html = new htmltagger();
$html->setTitle('wowTitle');
当你 设计
完了你的网页,你还可以:
// 当生成了网页后用redis来缓存网页。
// redis服务器默认设置成 localhost:6379 ,默认 300 秒的过期时间。
$html->redis($host,$port,$exp_time);
$html->setHead($head)->setBody($body)->setTitle('wowTitle')->prn(); //很装逼的串联~
## 当然你还能把上面那俩写成一起:
$html->redis()->setHead($head)->setBody($body)->setTitle('wowTitle')->prn();