Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中输出内容,不带echo_Php_Html - Fatal编程技术网

在PHP中输出内容,不带echo

在PHP中输出内容,不带echo,php,html,Php,Html,不使用echo就可以在PHP中输出类似于something的内容吗?假设我有一个用于显示数据库信息的类文件,但我希望它是纯PHP,并且没有大的echo语句。我可以这样做还是需要使用echo 谢谢请尝试关闭并重新打开PHP标记: # PHP CODE ?> <h3>Something</h3> <?php #MORE PHP CODE #PHP代码 ?> 某物 有很多方法,print()-die()-exit()、HTML、herdoc和nowdoc: <

不使用echo就可以在PHP中输出类似于
something
的内容吗?假设我有一个用于显示数据库信息的类文件,但我希望它是纯PHP,并且没有大的echo语句。我可以这样做还是需要使用echo


谢谢

请尝试关闭并重新打开PHP标记:

# PHP CODE
?>
<h3>Something</h3>
<?php
#MORE PHP CODE
#PHP代码
?>
某物

有很多方法,
print()
-
die()
-
exit()
、HTML、
herdoc
nowdoc

<?php

print("<h3>Something</h3>");
  • 这可能就是你要找的

    • 这可能就是您正在寻找的,使用:


      是的,使用系统/框架。“但我希望它是纯PHP”-echo是纯PHP。您可以采用面向对象的方式,让类具有使用echo的方法。如果您的意思是不希望整个HTML文件都出现在echo中,那么可以
      包含
      一个HTML或PHP文件,其中包含PHP范围之外的标记;或者,如果你真的想掌握技术,你也可以使用
      print
      ,但这并不能改变什么,真的
      <?php
      
      die("<h3>Something</h3>");
      
      <?php
      
      exit("<h3>Something</h3>");
      
      <!doctype html>
      <head></head>
      
      <body>
      <?php
      // some code
      ?>
      
      <h3>Something</h3>
      <?php
      // some other code
      ?>
      </body>
      
      </html>
      
      <?php
      $str = <<<'EOD'
      Example of string
      spanning multiple lines
      using nowdoc syntax.
      EOD;
      
      /* More complex example, with variables. */
      class foo
      {
          public $foo;
          public $bar;
      
          function foo()
          {
              $this->foo = 'Foo';
              $this->bar = array('Bar1', 'Bar2', 'Bar3');
          }
      }
      
      $foo = new foo();
      $name = 'MyName';
      
      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;
      ?>
      
      <?= <<<EOT
      <h1>
          This is some PHP text.
          It is completely free
          I can use "double quotes"
          and 'single quotes',
          plus $variables too, which will
          be properly converted to their values,
          you can even type EOT, as long as it
          is not alone on a line, like this:
      </h1>
      EOT;
      
      ?>