Page 2 of 2

Re: Function echo/print problem

Posted: Mon Nov 22, 2010 5:24 pm
by r3negade
Thanks a ton for all the feedback! This forum is really useful!

The 'hidden' thing wouldn't work though, because this is part of an Ajax page updater and I want to make sure to save as much bandwidth as possible.
That's why I'm using md5 to check if there is new content.

I eventually solved my problem by replacing printf with sprintf and storing (with .=) everything in a variable which is then returned.
So my problem was pretty much solved in the end anyway.

Thank you everybody once again for the feedbackz0rz!

Re: Function echo/print problem

Posted: Mon Nov 22, 2010 5:28 pm
by phphelpme
excellent, I was just looking into sprintf on google for you... lol

Glad you have sorted out the issue you were having... its hard to get a full picture of what you are trying to achieve without all the coding to see the full story. Well done pal.

Jason.

Re: Function echo/print problem

Posted: Mon Nov 22, 2010 5:33 pm
by Neilos
phphelpme wrote:its hard to get a full picture of what you are trying to achieve without all the coding to see the full story.
Agree lol.

sprintf would be good, something like;

Code: Select all

<?php
function foo() {
        $apples = 36;
        $trees = 5;
        $monkeys = 1;
        $bananas = 56;
        $string = sprintf("There are %2$s apples in the %1$s trees with %s monkeys and %s bananas.<br />", $apples, $trees, $monkeys, $bananas);
        
        $bees = 234;
        $dogs = 2;
        $string .= sprintf("There are %d bees, and %d dogs.", $bees, $dogs);
        
        return $string;

}

$bar = md5(foo());
echo $bar;
?>
Glad you got it fixed.