Heim  >  Artikel  >  Backend-Entwicklung  >  php中echo语句只是输出到上一层吗?

php中echo语句只是输出到上一层吗?

WBOY
WBOYOriginal
2016-06-06 20:44:07850Durchsuche

<code><?php $url = "http://www.somewebsite.com"; ?> 
   
   
<meta http-equiv="refresh" content="1;  
url=<?php echo $url; ?>" charset="utf-8">   
   
   
页面只停留一秒……  
 

</code>

如果是只需要$url的值,为什么不能直接引用,而要用echo语句?个人理解是echo只是输出到上一层,如果在最外层就输出到显示器,如果在低层就输出到外面一层。是这样吗?
php菜鸟,为自己的无知感到抱歉。已经查过php手册了,给出的解答很含糊,无法解决问题。

回复内容:

<code><?php $url = "http://www.somewebsite.com"; ?> 
   
   
<meta http-equiv="refresh" content="1;  
url=<?php echo $url; ?>" charset="utf-8">   
   
   
页面只停留一秒……  
 

</code>

如果是只需要$url的值,为什么不能直接引用,而要用echo语句?个人理解是echo只是输出到上一层,如果在最外层就输出到显示器,如果在低层就输出到外面一层。是这样吗?
php菜鸟,为自己的无知感到抱歉。已经查过php手册了,给出的解答很含糊,无法解决问题。

echo — 输出一个或多个字符串
echo会把后面的变量转化成字符串然后输出到文件中。
如果直接引用不是字符串的变量就悲剧了。

你在网上搜索一下flush和ob_flush区别
下面是我写的

<code><?php echo ('aaa');
    flush();
    sleep(10);
    ob_flush();
    flush();
</code></code>

10秒后出现aaa,是不是可以猜测echo输出到php“末端”,还没输出到apache
我也是菜鸟,可能不对

echo是把东西打印到输出流里面
如果本地执行的话输出流就是标准输出(控制台)
由服务器执行的话输出流就是网络流了

尖括号标签外面的文本相当于原封不动输出

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn