dongshi1868 2011-11-24 05:27
浏览 16
已采纳

PHP中的自定义HTML标记

When I was playing around with Joomla! source code, I saw such as code (or similar to this one, I am not pretty sure since it was a while back then):

<juc:place name="module" some-other-attributes/>

I am not telling it was exactly like the one above but I was surprised actually when I saw Asp.NET-like custom tags:

<asp:Label ID="lblLabel" runat="server"/>

I am now wondering how to accomplish same thing or similar in PHP like they did in Asp.NET. Is there any library for framework for this or so forth?

Do I need to write a parser which parses my php code and searches for such tags and replaces them with what's corresponding like Asp.NET replaces <asp:Label/> with <span/>

My personal preference:

I like what Asp.NET did by separating code-behind from design-view or html from c# code. And using asp.net's server-side controls enable developer to access html control from code-behind easily. It sounds like separation of concerns and I am wondering if there is any project or way which has done same thing already?

  • 写回答

3条回答 默认 最新

  • douqie1816 2011-11-24 05:32
    关注

    If you use an approach, where presentation layer is stored separately from execution logic (for instance, a templating engine), then it is quite easy to create a parser which looks for specific code in HTML and replaces it with shomething else. You could make your own "SMARTY" language.

    However, if your code is just "executable PHP" with no layer separation, you can't do such replacements (as it is directly executed by PHP scripting engine). By "executable php" I mean something like this:

    <html>
      <head>
      ...
      </head>
      <body>
      <?php echo "Hello world"?>
      </body>
     </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 SQL Server下载
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角