dongwo2222 2017-11-15 23:54
浏览 79

为什么只有PHP允许在HTML代码中,但其他语言使用CGI? [关闭]

For example, why developers of Python don't make the interpreter for using Python like PHP in HTML code?

I hope my question is not very stupid, if so, sorry about that.

  • 写回答

1条回答 默认 最新

  • dtnrsmi824877 2017-11-16 00:25
    关注

    PHP was initially designed primarily as a programming language for creating web applications (the name stands for Personal Home Page). To make this easier, they tightly integrated the language into the web pages. In fact, in early versions of PHP, the code was embedded in HTML comments (similar to the way early Javascript had to be embedded). The PHP History page shows examples of this (this was called PHP/FI -- PHP Forms Interpreter):

    <!--include /text/header.html-->
    
    <!--getenv HTTP_USER_AGENT-->
    <!--ifsubstr $exec_result Mozilla-->
      Hey, you are using Netscape!<p>
    <!--endif-->
    

    Later on, the name PHP became the recursive acrynym PHP Hypertext Preprocessor. This indicates that it's intended to be embedded in HTML, much the way C preprocessor code is embedded in C and C++ programs.

    The embedded nature makes it easy to write web pages with lots of static HTML interspersed with dynamic code. In any other language, you'd need hundreds or thousands of print statements, while PHP allows you to just escape out of scripting mode into raw output for all the static parts.

    There's no reason other languages couldn't be embedded into HTML in similar ways. But the designers simply didn't have that as a priority, they intended them as more general purpose languages, so they didn't put this feature into them. PHP can be used as a standalone programming language (my company uses it extensively in cron jobs), it's just not its original design emphasis.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器