Web Analytics Made Easy -
StatCounter Something like qq~Text~; (from Perl) in PHP? - CodingForum

Announcement

Collapse
No announcement yet.

Something like qq~Text~; (from Perl) in PHP?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Something like qq~Text~; (from Perl) in PHP?

    In Perl I use qq~Some text~; a lot and I'm looking for something like this in PHP.

    For those who don't know perl, let me explain what it does:
    It enables you to write on multiple lines without extra functions (is possible in PHP with just the "Text [new line] more text")
    But it also makes it possible to write text whitout have to escape all characters; like ", <, $, etc.

    Anyone?

    Thanks in advance,
    Mzzl, Chris
    My Website
    010100010011110101110100011011110111000001101000

  • #2
    In php to write on a new line just do
    PHP Code:
    echo "some text \n more text on another line" 
    Note : This will make a new line in the source code. If you want a new line on the screen you need to replace the \n by <br>
    You don't need to escape $ and < in php. Just " or ' and \ I think
    I don't suffer from insanity, I enjoy every single minute of it!

    Comment


    • #3
      Also,

      If your in a conditional loop I think this works (although I haven't tried it)

      <?php
      if(some_condition) {//write if condition is true
      ?>

      <table border="5" cellpadding="1">
      <tr><td>This is the life, I'm going to write a backslash \.</td></tr>
      </table>

      <?php
      }// end writing
      else {// begin writing for false condition
      ?>

      Nope ain't gonna do it! OK?

      <?php
      }// end false condition writing
      ?>
      Create accessible online surveys -::- Koobten.com - compare netbook prices and reviews -::- Affordable, reliable hosting for less than $20 per year
      Zend Certified Engineer

      Comment


      • #4
        It does work

        And not only in conditions, just anywhere
        I don't suffer from insanity, I enjoy every single minute of it!

        Comment


        • #5
          Additionally, perhaps the heredoc syntax is suited to your needs. Although it parses variables still... have a look at

          De gustibus non est disputandum.

          Comment


          • #6
            You an also just exit out of the PHP block and print HTML directly (which is, technically, faster than doing ECHO, from a machine speed/time point of view). Of course, then you are going to have to enclose any of your variables with <?= and ?>.

            PHP Code:
            <?
                
            //preceding code, if any
                
            if ($c['noticestat']) {
                
            //html block
            ?>
                <html lang="en_US">
                    <head>
                        <title><?=$title['curvar'];?></title>
                    </head>
                    <body bgcolor="#000000" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">
                        <table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
                            <tr>
                                <td width="100%" height="100%" align="center" valign="middle" class="noticeTxt"><?=$c['noticemess'];?><br/>
                                <br/>.( <?=$c['sitename'];?> ).</td>
                            </tr>
                        </table>
                    </body>
                </html>
            <?
                
            }
                
            //back to PHP
                //additional code, if any
            ?>
            Edit : evil missing bracket!
            Last edited by Feyd; Jul 11, 2002, 01:01 PM.
            Moderator, Perl/CGI Forum
            shadowstorm.net - subvert society

            Comment


            • #7
              That "exiting" PHP is a good idea and solves my problem, for a part, but I'd also like to know if there's a way in wich I don't have to escape "...

              Thanks to all of you for your help.
              My Website
              010100010011110101110100011011110111000001101000

              Comment


              • #8
                Yup, this can be done... like so

                PHP Code:
                echo<<<code
                <form name="edit=web"  method="post" action="edit_Prem_table.php?edit=1&id=<?=row[id];?>">                        
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                      <td valign="middle" width="20%"> 
                        <div align="center">
                code;
                print $row["team"];
                echo<<<code
                </div>
                      </td>
                      <td width="20%" valign="middle"> 
                        <div align="center"> 
                          <input type="text" class="formfield" name="newplayed" size="2" value="
                code;
                Hope that is clear... the code thingcan be anyhting!

                Jee
                Jeewhizz - MySQL Moderator
                http://www.sitehq.co.uk
                PHP and MySQL Hosting

                Comment


                • #9
                  Thanks, that's it
                  My Website
                  010100010011110101110100011011110111000001101000

                  Comment

                  Working...
                  X