dongzheng3113 2011-12-30 04:38
浏览 38
已采纳

PHP:可以防止功能回显到屏幕?

Ok I know the title is a bit confusing as I can't think of a good way to explain it. There is this function which I don't have access to and it looks something like this:

<?php function myFunction() {
?> '<img src="one.jpg" />';
<?php } ?>

Ok so everytime that function is called, it echo's the img tag. But what if I want to manipulate the img tag before it echos to the screen? Is it possible?

I want to assign it to a variable first, manipulate it and then I will echo it out. Something like this:

$image_src = myFunction();
$image_src = preg_replace('/s.*"/', $image_src);
echo $image_src;

Something like this possible?

  • 写回答

2条回答 默认 最新

  • douza9835 2011-12-30 04:39
    关注

    Use output buffering:

    ob_start();
    myFunction();
    $output = ob_get_clean();
    

    after that, $output will contain the html that was echoed inside the function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题