Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Posts
    61

    Unanswered: caputure result html into a variable

    hello everyone.
    I'd like to be able to do something like this:
    $noam = "

    $i = 1;
    while ($i < 10)
    {
    $i = $i + 1 ;
    echo $i;
    }";

    echo $noam;

    Right now it doesn't work at all. Echo $noam shows the code, not the html result of the code...

    any idea how to make it work? whecn I echo $noam I should get 123456789

    Thanks
    Noam

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    Echo $noam shows the code, not the html result of the code...
    First off, it shows the code, because that's what you are assigning to the variable $noam. You are enquoting the code. That assigns the string to your variable. What you want to do is to append each digit from $i as a string to the end of $noam.

    Also, get rid of the call to echo $i;. This should be where you are adding the digit to your string...

    And next time, use php tags around your code.

  3. #3
    Join Date
    Dec 2003
    Posts
    61
    <?pjp
    $i = 1;
    while ($i < 10)
    {
    $i = $i + 1 ;
    echo $i;
    }";
    ?>

    this works by itself now. I get 123456789

    How do I assign the <html><body>12345679</body></html> to the variable $noam?

  4. #4
    Join Date
    Apr 2006
    Posts
    1

    Tip: RTFM!

    How do I assign the <html><body>12345679</body></html> to the variable $noam?
    noamkrief,

    You should really read the manual before asking questions like this. There are extensive online manuals and "how-to's" available everywhere on the web. Check www.phpfreaks.com for a stack of tutorials.

    But to answer your question you simply do this...

    <?php

    $noam = "";

    $i = 1;

    while ($i < 10)
    {
    $i = $i + 1 ;
    echo $i;
    // The following line will add the value of $i to the end of the string $noam
    $noam = $noam . $i;
    };

    // The following line will produce the result you wanted
    $noam = "<html><body>".$noam."</body></html>";

    ?>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •