Change language

How to display HTML in PHP?

When building a web application in PHP , we often have to print or output multiple results as HTML . We can do this task in a variety of ways. Some of the methods are described here:
  • Using echo or print : PHP echo or print can be used to display HTML markup, javascript, text, or variables. Example 1:This example uses PHP echo to display the result. $name = "GeeksforGeeks" ; echo "

    Hello User, < / h1 >

    Welcome to {$name} < / p> " ; ?> Output: Example 2:This example uses PHP print to display the result. $name = "GeeksforGeeks" ; print "

    Hello User, < / h1 >

    Welcome to {$name} < / p> " ; ?> Output:

  • Using the echo shortcut or HTML splitting.The PHP echo shortcut can be used to display the result of any expression, the value of any variable, or HTML markup. Example 1:This example uses the shortcut PHP echo to display the result. < tbody> $name = "GeeksforGeeks" ; ?>  
    Hello User, < / h1 >

    { $name } welcomes you < / h1 >" ?> Output: Example 2:separating HTML from PHP $num = 2; for ($i = 1; $i < = 10; $i ++) { ? & Gt;

     * = < / p>  
    } ?> Output:

  • Using heredoc.We can use < < <heredoc to print html. < < <must be followed by an identifier and a newline. The same identifier is used to close the body of the heredoc. Syntax:
    < < < GFG // HTML Markup GFG; 
    Note:The final identifier must not be indented.Example : echo < < < GFG

    GeeksforGeeks < / h1 >

    I am in heredoc with identifier ’GFG’ . < / p> GFG;  
    ?>
    Output:

  • Shop

    Best laptop for Sims 4

    $

    Best laptop for Zoom

    $499

    Best laptop for Minecraft

    $590

    Best laptop for engineering student

    $

    Best laptop for development

    $

    Best laptop for Cricut Maker

    $

    Best laptop for hacking

    $890

    Best laptop for Machine Learning

    $950

    Latest questions

    NUMPYNUMPY

    psycopg2: insert multiple rows with one query

    12 answers

    NUMPYNUMPY

    How to convert Nonetype to int or string?

    12 answers

    NUMPYNUMPY

    How to specify multiple return types using type-hints

    12 answers

    NUMPYNUMPY

    Javascript Error: IPython is not defined in JupyterLab

    12 answers

    Wiki

    Python OpenCV | cv2.putText () method

    numpy.arctan2 () in Python

    Python | os.path.realpath () method

    Python OpenCV | cv2.circle () method

    Python OpenCV cv2.cvtColor () method

    Python - Move item to the end of the list

    time.perf_counter () function in Python

    Check if one list is a subset of another in Python

    Python os.path.join () method