Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

php - How to make echo table with two div tag?

How to make echo for table with div ? Table do not work if I need to do echo.

My proposal with echo (not work):

<?php
    echo "<div class="container">
        <div class="main">
           <h2>User info</h2><hr/>
                <form id="form1" name="form1" method="post" action="input_form_02_qA_01.php">
                    <label>Name:<span>*</span></label><br />
                    <input type="text" name="nick" id="nick" placeholder="" required/>
                    <label>Email address:
                    <input type="text" name="email" id="email" placeholder="" required/>
                    </label>
                    <br/>
                    <label>Age:<span>*</span></label><br />
                    <input type="number" name="age" id="age" required/>
                    <label>Sex:<span>*</span></label><br />
                    <input type="radio" name="sex" value="man" required>Man
                    <input type="radio" name="sex" value="woman" required>Woman
                    <p>
                    <label>
                    <input type="submit" name="submit" id="Submit" value="Go to page 2" />
                    </label>
                </form>
        </div>
    </div>";
 ?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Take a look at php's heredoc and nowdoc.

Heredoc text behaves just like a double-quoted string, without the double quotes. This means that quotes in a heredoc do not need to be escaped, but the escape codes listed above can still be used. Variables are expanded, but the same care must be taken when expressing complex variables inside a heredoc as with strings.

Nowdocs are to single-quoted strings what heredocs are to double-quoted strings. A nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc. The construct is ideal for embedding PHP code or other large blocks of text without the need for escaping. It shares some features in common with the SGML construct, in that it declares a block of text which is not for parsing.

heredoc example:

echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': x41
EOT;

gives

My name is "MyName". I am printing some Foo. Now, I am printing some Bar2. This should print a capital 'A': A

nowdoc example:

echo <<<'EOT'
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should not print a capital 'A': x41
EOT;

gives

My name is "$name". I am printing some $foo->foo. Now, I am printing some {$foo->bar1}. This should not print a capital 'A': x41

or in your case:

echo <<<'HTML'
<div class="container">
    <div class="main">
       <h2>User info</h2><hr/>
            <form id="form1" name="form1" method="post" action="input_form_02_qA_01.php">
                <label>Name:<span>*</span></label><br />
                <input type="text" name="nick" id="nick" placeholder="" required/>
                <label>Email address:
                <input type="text" name="email" id="email" placeholder="" required/>
                </label>
                <br/>
                <label>Age:<span>*</span></label><br />
                <input type="number" name="age" id="age" required/>
                <label>Sex:<span>*</span></label><br />
                <input type="radio" name="sex" value="man" required>Man
                <input type="radio" name="sex" value="woman" required>Woman
                <p>
                <label>
                <input type="submit" name="submit" id="Submit" value="Go to page 2" />
                </label>
            </form>
    </div>
</div>
HTML;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...