search
HomeBackend DevelopmentPHP ProblemThree ways to embed html code in php programs

Three ways to embed html code in php programs

The three methods for embedding html code into php programs are as follows:

The first is to add PHP

large sections of html to HTML In the code, in each place where php needs to be executed,

For example, line7-9:

 1 <head>
 2     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 3     <meta http-equiv="Content-Language" content="zh-CN" />
 4     <title>Hello World</title>
 5 </head>
 6 <body>
 7     <?php
 8     echo "Hello world!这是正文";
 9     ?>
10 </body>
11 </html>

The second method uses echo to output HTML.

Because some HTML elements have double quotes, the content output by echo is enclosed in single quotes to avoid errors and save the escaping step. For example, code like this:

(Learning video sharing: php video tutorial)

  <?php
      if(!$_POST){
      echo ‘<form action="" method="post">
      服务器地址:<input type="text" name="host" value="localhost" /><br />
      数据库账号:<input type="text" name="user" value="" /><br />
      数据库密码:<input type="password" name="pwd" value="" /><br />
      指定数据库:<input type="text" name="db" value="test" /><br />
      <input type="submit" value="确定"/>
      </form>‘;
     }
 ?>

Or this kind of code with escape symbols:

<?php
     echo "<input type=\"submit\" value=\"确定\"/>" ;
 ?>

The third way is to use the (

  <?php
      print <<<EOT
      <div class="slidecont">{$label[deepblue_mainslide]}</div>
     <div class="newcontainter">
          <div class="head">{$label[deepblue_mainh1]}</div>
          <div class="cont" id="Tab1">{$label[deepblue_maint1]}</div>
          <div class="cont" id="Tab2">{$label[deepblue_maint2]}</div>
      </div>
      <a href="$rs[url]" title="$rs[descrip]" target="_blank">$rs[name]</a>
 EOT; 
 ?>

The document between "The advantage is that it is convenient to output large sections of HTML, no escaping is required, and variables can be quoted.

But there is one more thing to note when using the (

The EOT tag here can be replaced with any tag, such as print

Related recommendations: php tutorial

The above is the detailed content of Three ways to embed html code in php programs. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor