Home  >  Article  >  Backend Development  >  php调用有输出的函数,但是不输出,赋值到变量中。解决思路

php调用有输出的函数,但是不输出,赋值到变量中。解决思路

WBOY
WBOYOriginal
2016-06-13 10:08:12910browse

php调用有输出的函数,但是不输出,赋值到变量中。
假如有一个函数,如下:
function a(){
  echo "abc";
}
那么,每次调用a()函数的时候就会输出内容,如何实现调用后不输出,而赋值到一个变量中。

------解决方案--------------------

PHP code
<?phpfunction a(){  echo "abc";}ob_start();a();$str = ob_get_contents();ob_end_clean();echo $str;?><div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn