GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Oct-2009, 07:33
MacForMore MacForMore is offline
New Member
 
Join Date: Oct 2009
Posts: 1
MacForMore is on a distinguished road
Question

Can't get multiline with heredoc


I'm working some samples, learning PHP, and I can't get the heredoc construct to output multiline text in the browser.

My samples come from an O'Reilly book and various websites.

Am I doing something wrong?

I'm a mac newbie doing this in Netbeans on the mac with MAMP 1.8.2 installed. Mamp has PHP 5 with Zend Extensions (don't know what that is). I copied the text for index.php to another editor, thinking it might be something with netbeans, but that didn't help.

this code, below, outputs only one line.

PHP Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        $variables = "a test variable";
$string = <<< END_OF_STRING
            this is a multi-line
            string containing variables
            and single quotes '
            and double quotes "
            and slashes \
            do not need to be escaped
END_OF_STRING;
        echo $string
        ?>
    </body>
</html> 


the output in the browser looks like this
Quote:
this is a multi-line string containing a test variable and single quotes ' and double quotes " and slashes \ do not need to be escaped
  #2  
Old 04-Oct-2009, 14:16
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: can't get multiline with heredoc


Quote:
Originally Posted by MacForMore
...

the output in the browser looks like this...

You created a string and the browser displayed the string.

If you want to force parts of the multi-line string to appear on separate lines, you put a "break" tag wherever you need it.


For example
PHP Code:

<?php
$string = <<< END_OF_STRING
            This is a multi-line
            string containing several goodies. <br /><br />
            Single quotes ' <br />
            and double quotes " <br />
            and slashes \ <br />
            do not need to be escaped!
END_OF_STRING;
        echo $string;
?>


Browser should show something like the following:

Code:
This is a multi-line string containing several goodies. Single quotes ' and double quotes " and slashes \ do not need to be escaped!


Regards,

Dave
Last edited by davekw7x : 04-Oct-2009 at 14:47.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
multiline editbox. ib_alam MS Visual C++ / MFC Forum 1 28-Mar-2005 21:17
Please help to solve me a problem with multiline texrbox and checkbox mithila MS Visual C++ / MFC Forum 0 08-Sep-2004 23:08
Displaying the \n character in a Multiline Edit Box sami MS Visual C++ / MFC Forum 4 05-Aug-2004 04:11
echo <<< HEREDOC doesn't work... pepee MySQL / PHP Forum 14 03-Apr-2004 15:44

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:12.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.