PHP Literal output with function definition?>

When I wrote PHP code in the past, I was often embarrassed by the fact that I had to insert my HTML code into calls to print, echo, or the like. To some extent, this is facilitated by the ability to make parts of the code literally output by closing the PHP tag and reopening it after exiting, for example:

<?php /*DoSomeStuff*/ ?>
Some HTML code.
<?php /*SomeMorePHP*/ ?>

However, I never understood how this relates to functions. For example, it is not clear to me whether:

<?php
function myFunction() {
?>
Some HTML
<?php
}
?>

Will it generate a function that, after a call, displays this HTML if the function is parsed as empty, but displays this HTML during parsing, or none of them, or if this construction is completely illegal?

, - PHP, , undefined , , PHP, , .

- , .

+4
2

, , : (PHP Docs), doesn 't , , BIG frameworks.

, :

function htmlOut() {
    ?>
    Some HTML output
    <?php
}


htmlOut();

, , MediaWiki ( , , ) , .

/**
 * Outputs the entire contents of the (X)HTML page
 */
public function execute() {
    /**
     * some code
     */
    // Output HTML Page
    $this->html( 'headelement' );
    ?>
    <div id="mw-page-base" class="noprint"></div>
    <div id="mw-head-base" class="noprint"></div>
    <div id="content" class="mw-body" role="main">
        <a id="top"></a>

        <?php
    /**
     * some more code
     */
}

: MediaWiki GitHub

+2

, , , , HTML .

, , .

, :

<?php if ($expression == true): ?>
  HTML1
<?php else: ?>
  HTML2
<?php endif; ?>

PHP HTML ? , , , . , , /, " ". , swich

: http://php.net/manual/en/language.basic-syntax.phpmode.php # 1

+1

Source: https://habr.com/ru/post/1617033/


All Articles