Function returns echo $something, any way to use it in variables?

Discussion in 'PHP' started by littlebobek, Jul 11, 2007.

  1. #1
    Hi,

    I have this problem.

    The function returns result as echo and I'm not allowed to change it. Is there any way to use it in variables?

    This example writes output before h1 tags and the $variable in h1 does not write anything.

    
    $variable = thatfunction();
    
    <h1><? echo $variable; ?></h1>
    PHP:
    I would really appreciate any help.
     
    littlebobek, Jul 11, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    <?php
    ob_start();
    thatfunction();
    $variable = ob_get_contents();
    ob_end_clean();
    ?>
    
    <h1><?php echo $variable; ?></h1>
    
    PHP:
     
    nico_swd, Jul 11, 2007 IP
    littlebobek likes this.
  3. littlebobek

    littlebobek Peon

    Messages:
    763
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you, that is exactly what I needed. A rep on it's way. ;)

    Excellent
     
    littlebobek, Jul 11, 2007 IP