I need your help urgently

Joined
Aug 11, 2023
Messages
3
Reaction score
0
1692045364168.png

don't display $name. what is reason?
 
Joined
Sep 4, 2022
Messages
128
Reaction score
16
PHP:
$a_name = "Sami";

$sentenceText = 'hello by ' . $a_name . " by concatenation" ;

It's just concatenation missing , the "." make it perfectly.
you don't need echo , because you're processing a String Interpolation , a String Build !

the other case is how to put php function or value in the html ?


PHP:
<html>

<head>
<title> <?php echo("Hello !"); ?> </title>
</head>

<body>
<?php echo("Why not by the body ?") ; ?>


</body>
</html>

you have two methods...
  • a String is insert by php in an html code. the html is store in a php $var.
  • a html string needs to integrate a value from Php level
 
Last edited:
Joined
Jul 4, 2023
Messages
366
Reaction score
41
You can use notation even like this to put some value from php variable in to the text.

e.g.
PHP:
<?php
    $name = 'John';
    $html = "
        <!DOCTYPE html>
        <html>
            <head>
                <title>PHP and HTML</title>
            </head>
            <body>
                <h1>Welcome to my PHP website</h1>
                <p>This is a paragraph of text $name</p>
            </body>
        </html>
    ";

    echo $html;
?>

or

PHP:
<?php
    $name = 'John';
    $html = "
        <!DOCTYPE html>
        <html>
            <head>
                <title>PHP and HTML</title>
            </head>
            <body>
                <h1>Welcome to my PHP website</h1>
                <p>This is a paragraph of text {$name}</p>
            </body>
        </html>
    ";

    echo $html;
?>

or

PHP:
<?php
    $name = 'John';
    $html = <<<END
        <!DOCTYPE html>
        <html>
            <head>
                <title>PHP and HTML</title>
            </head>
            <body>
                <h1>Welcome to my PHP website</h1>
                <p>This is a paragraph of text $name</p>
            </body>
        </html>
END;

    echo $html;
?>


[ nowdoc syntax ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top