Results 1 to 14 of 14

Thread: Echoing echos?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Echoing echos?

    Hi,

    How do I echo echo's? I need it to include pages with these commands.
    Ex.

    PHP Code:
    echo "
            echo "
    Blah blah ";
    "


  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,651

    Re: Echoing echos?

    I am completely confused

    What is the problem with your code?

    Is it

    1) The quotes inside quotes? If so, use the backslash to escape the inside quotes (as in $var = "... \" ... "), or better yet, use single quotes for the enclosing string.

    or
    2) Getting data from a file and echoing it?

  3. #3
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Echoing echos?

    Is what your saying?

    That you need to "include" "files" with echo's in them?
    include('pagename.php');

    Or is it something like this
    PHP Code:
    <?php
    echo"
    <H1>This is an echo inside an echo - double quotes x2</H1>
    echo\"Wassup\";
    "
    ;
    //Also this works
    echo'
    <H1>This is an echo inside an echo - double quotes in single quotes</H1>
    echo"Wassup";
    '
    ;
    //Also this works
    echo"
    <H1>This is an echo inside an echo - single quotes in double quotes</H1>
    echo'Wassup';
    "
    ;
    //Ect
    ?>
    You know... what pengate said.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Echoing echos?

    Well, the code is
    PHP Code:
    $tekst = "
        Velkommen til din logbog! Her kan du føre regnskab med din motion. Hvis du løber tør for aktivitets-idéer,
        så kan du altid tjekke Idé-maskinen, der automatisk foreslår en tilfældig aktivitet.
        <br>
        Varigheden angives i timer; men har du f.eks. motioneret i 1½ time, så skal du skrive \"1.5\" - med punktum og ikke komma.
        <p><center><b>Jeg har indtil videre lavet dette:</b><br>
              <table width='100%' border='1' cellspacing='0' cellpadding='0'>
              <br>
              <tr>
              <td align='center' width='33%'><b>Dato</b></td>
              <td align='center' width='33%'><b>Aktivitet</b></td>
              <td align='center' width='33%'><b>Varighed</b></td>
              </tr>';
    <?php
            $n
    =0;
            
    $brugernavn ". $_SESSION['s_username'].";      
            
    $query mysql_query('SELECT aktivitet,dato,varighed FROM $brugernavn') or die(mysql_error());
            while (
    $newArray mysql_fetch_array($query)) {
            
    $aktivitet  ".$newArray['aktivitet'].";
            
    $dato ".$newArray['dato'].";
            
    $varighed ".$newArray['varighed'].";
            
    $n=$n+$varighed;
            if (
    $aktivitet==NULL) {
            echo 
    '<center><br>Intet endnu</center>';
            }else{
            echo 
    "
            <tr>
              <td align='center' width='33%'>
    $dato</td>
              <td align='center' width='33%'>
    $aktivitet</td>
              <td align='center' width='33%'>
    $varighed time(r)</td>
              </tr>
              "
    ;
              }
              }
              echo 

          </table>
          <br><b><center>Ialt: 
    $n time(r)</b></center><br>
          <br><a href='aendr.php'>Ændr aktiviteter</a>
          <br><br>
    "
    ;
          echo 
    "
               <table width='100%' border='0' cellspacing='0' cellpadding='0'>
            <tr> 
              <td align='center' width='33%'>Dato</td>
              <td align='center' width='33%'>Aktivitet</td>
              <td align='center' width='33%'>Varighed (timer)</td>
            </tr>
            <tr> 
              <td colspan='3' align='center'><form name='form2' method='post' action='addlog.php'>
                  <input name='dato' type='text' size='25'>
                  <input name='aktivitet' type='text' size='25'>
                  <input name='varighed' type='text' size='25'>
                  <p align='right'>
                  <input type='submit' name='Submit2' value='Tilf&oslash;j'></p>
                </form></td>
            </tr>
          </table>
          <b>Idé-maskinen:</b><br>
          END;
          
    $ide = mysql_query('SELECT * FROM idemaskine') or die(mysql_error());
          
    $rows = mysql_num_rows($ide);
          
    $id = rand(1,$rows);
          
    $data = mysql_query(\"SELECT aktivitet FROM idemaskine WHERE id = '$id'\") or die(mysql_error());
          
    $row = mysql_fetch_array($data);
          
    $aktivitet = ".$row['aktivitet'].";
          echo<<<END
          <table width='100%' border='1' cellspacing='0' cellpadding='0'>
          <tr>
              <td height='30' bgcolor='#CCCCCC' align='center'>
    $aktivitet</td>
              </tr>
          </table>
          </center>
          <a href='logout.php'>Log ud</a>
          "
    ;
    }
    ";
    This variable, $tekst, is echoed from another page that includes (include("blahblah.php")).

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,907

    Re: Echoing echos?

    I have a question? Where on earth did you learn to write PHP like that? I wouldl ike to meet the person who taught you .... and kill him.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Echoing echos?

    It's self-taught and I don't usually write it this way. I kinda tried to work it around to make it work :P

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,907

    Re: Echoing echos?

    Fact is, no one is going to want to help you if you don't put the effort into writing clean readable code. Incase you didn't already know:
    • Indent your code. Whenever you use braces, {} tab out:
      This is good:
      PHP Code:
      while(true) {
          if(
      $condition) {
              echo(
      'blah');
          }

      This is bad:
      PHP Code:
      while(true) {if($condition) {
      echo(
      'blah');
      }

    • I have no idea what is meant by this:
      PHP Code:
      $brugernavn ". $_SESSION['s_username']."
      But you can embed variables in side double quoted strings as follows:
      PHP Code:
      $string "Hello i am an embeded {$var} and so is {$_SESSON['blah']}"
    • PHP is not Perl. It is an HTML embedded scripting language. DO NOT echo huge chunks of HTML at a time:

      This is bad:
      PHP Code:
      echo "
              <tr>
                <td align='center' width='33%'>
      $dato</td>
                <td align='center' width='33%'>
      $aktivitet</td>
                <td align='center' width='33%'>
      $varighed time(r)</td>
                </tr>
                "

      This is good:
      PHP Code:
      ?>
      <tr>
          <td align="center" width="33%"><?php echo($dato?></td>
          <td align="center" width="33%"><?php echo($aktivitet?></td>
          <td align="center" width="33%"><?php echo($varighed?></td>
      </tr>
    • Single quotes should never be used for attribute vlaues in HTML.

    Use those tips above to edit the code you have and make it look respectable and get into the habbit of us coding properly, otherwise you will be the one who suffers.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Echoing echos?

    Ok, thanks. But that doesn't really answer my question :S

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Echoing echos?

    Hmm, I'll just try something else...something less stupid

  10. #10
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,907

    Re: Echoing echos?

    Quote Originally Posted by sveegaard
    Ok, thanks. But that doesn't really answer my question :S
    I deliberatly didn't answer your question and won't unless you make your code look more respectable.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: Echoing echos?

    Please be gentle to a newbie Ö

  12. #12
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Echoing echos?

    Quote Originally Posted by sveegaard
    Please be gentle to a newbie Ö
    VisualAd is not meaning to be horrible, but it is hard for other people to read code which is badly formatted. It can take a long time to understand badly formatted code to see a simple problem.

  13. #13
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,907

    Re: Echoing echos?

    I understand that you are new to PHP - but If you have a go and try (I've given you are few tips) and post what you come up with. I'll be happy to help. I am not happy to help those who do not put the effort in though.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  14. #14
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Echoing echos?

    Hes right, i was bugging visualad on msn earlier, as he was refusing to answer my question i learnt it myself.

    Now code right!

    ILMV
    My Flickr Stream »


    My Sites » BlogTwitterFlickr

Posting Permissions

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



Click Here to Expand Forum to Full Width