Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    Paris, France
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #3
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    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
    ?>

  • #4
    New Coder
    Join Date
    Jun 2002
    Location
    Paris, France
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    It does work

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

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Additionally, perhaps the heredoc syntax is suited to your needs. Although it parses variables still... have a look at

    http://www.php.net/manual/en/language.types.string.php

  • #6
    Regular Coder Feyd's Avatar
    Join Date
    May 2002
    Location
    Los Angeles, CA Maxim: Subvert Society
    Posts
    404
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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; 07-11-2002 at 06:01 PM.
    Moderator, Perl/CGI Forum
    shadowstorm.net - subvert society

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    369
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, that's it


  •  

    Posting Permissions

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