加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 在html中实现宏定义的方法

发布时间:2020-12-13 18:03:39 所属栏目:PHP教程 来源:网络整理
导读:我会做的很棒 define tag="myTag" options="3"h1 #1 /h1ul li #2 li #3/ul/define 然后使用它: myTag option="foo" option="bar" option="bean" / 我认为宏是 真的很大的优势. 解决方法是使用像m4这样的宏处理器,或者使用php来模拟宏的效果.还有其他要考虑
我会做的很棒
<define tag="myTag" options="3">
<h1> #1 </h1>

<ul>
  <li> #2
  <li> #3
</ul>

</define>

然后使用它:

<myTag option="foo" option="bar" option="bean" />

我认为宏是
真的很大的优势.

解决方法是使用像m4这样的宏处理器,或者使用php来模拟宏的效果.还有其他要考虑的技术吗?

也许显而易见,但C预处理器可以完成这项工作.

index._html

#define _em(a) <em> a </em>

#define _image(a,b) <img src="a" b/>

#define _list(a,b,c) <h1> a </h1> 
<ul> 
    <li> b </li> 
    <li> c </li> 
</ul>
<!-- ___________________________________________________ -->

<!doctype html>

<html> 


#define _theTile The Bar Title
#include "head._html"


<body>

_list(foo,bar,bean)

This is really _em(great)

_image(media/cat.jpg,)

_image(media/dog.jpg,width="25%" height="10px")

</body>

</html>

是head._html

<head>

    <meta charset="utf-8"/>
    <title> _theTile </title>

    <!-- more stuff ... -->

</head>

然后,

cpp -P index._html > index.html

生产:

<!doctype html>

<html> 

<head>

    <meta charset="utf-8"/>
    <title> The Bar Title </title>

    <!-- more stuff ... -->

</head>

<body>

<h1> foo </h1> <ul>     <li>  bar </li>     <li>  bean </li> </ul>

This is really <em> great </em>

<img src="media/cat.jpg"  />

<img src="media/dog.jpg"  width="25%" height="10px"/>

</body>

</html>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读