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

WBOY
Release: 2016-06-13 13:43:12
Original
1022 people have browsed it

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

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

PHP code

<?php function a(){
  echo "abc";
}
ob_start();
a();
$str = ob_get_contents();
ob_end_clean();
echo $str;
?> <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template