Function echo/print problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

r3negade
Forum Newbie
Posts: 4
Joined: Mon Nov 22, 2010 3:27 pm

Re: Function echo/print problem

Post 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!
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: Function echo/print problem

Post 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.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: Function echo/print problem

Post 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.
Post Reply