dqh1992 2011-09-01 02:44
浏览 28
已采纳

有没有更快的方法来做这样的html标签创建功能?

My friend and I who is a bit of a newbie like me were discussing writing a PHP function to do some shorthand html..

For example:

function hf($tag,$var) {

    return '<' . $tag . '>' . $var . '</' . $tag . '>';

}

echo hf('h1','howdy');

Of course, this 'shortcut' actually takes longer to write in the end than just:

<h1>howdy</h1>

I think its still even longer than if in php having to type:

$var = '<h1>howdy</h1>';

But maybe starts becoming a little more closer to being a shortcut when doing something like:

$var = '<div>' . hf('h1','howdy') . '</div>';

But really - its not a shortcut at all. Maybe only on larger tags with 3 or more characters does it start becoming a teeny shortcut.

I thought though we would take it to the experts out there to see if you have thought of a 'shorthand' way of producing html while working in php.

I think textmates shorthand is pretty excellent ie:

h1. howdy

That seems to trump them all but I haven't seen a textmate serverside parser or something like that out there.

Have you got a faster method for doing this? My friend and I both agree that all this open and closing and forward slashes gets a bit tedious and its a bit like finger dancing sometimes when you're working in php handling doing all the apostrophes and fullstops also.

  • 写回答

1条回答 默认 最新

  • dongmei9203 2011-09-01 03:38
    关注

    I think the "TextMate shorthand" you refer to is probably Textile, for which there is a good PHP parser (look for "Get Textile" in the right sidebar).

    A similar lightweight markup language is Markdown, a version of which is used here on Stack Overflow, and for which there are several good PHP parsers like this one.

    Finally there are languages like Haml and Jade that abstract away a lot of the repetition in HTML while providing a more complete templating featureset. Haml, too, has PHP libraries available.

    I usually end up writing Plain Old HTML, but when you want something a little (or a lot) tighter there are a lot of options.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教