Re: Using a heredoc in PHP as in Perl [message #171890 is a reply to message #171885] |
Thu, 20 January 2011 10:55 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma:
|
Senior Member |
|
|
El 20/01/2011 10:00, P E Schoen escribió/wrote:
> I am going to be using PHP to perform an HTML purification before the
> user's input from a form is presented to a Perl script which saves the
> content and presents it in HTML format.
> I am totally new to PHP and I have just a basic working knowledge of Perl.
Then, why don't you do it with Perl? I see little reason to add a second
server side technology under this conditions.
> In Perl, I use a heredoc
> which is done with a statement such as:
>
> print <<"END";
> My Text...
> END
>
> I found several references such as http://en.wikipedia.org/wiki/Heredoc
> to a similar means for PHP, but it did not work for me (parse error on
> line with the <<<):
As Luuk already said, the sensible place to find information about PHP
syntax is the PHP manual, not Wikipedia ;-)
>
> echo <<<EOF
> My Text...
> EOF;
I suppose the exact error is this:
Parse error: syntax error, unexpected $end, expecting T_VARIABLE or
T_END_HEREDOC or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN
If it's complaining about missing T_END_HEREDOC it's because EOF was not
recognised as heredoc end delimiter. From the manual:
«The closing identifier must begin in the first column of the line.
Also, the identifier must follow the same naming rules as any other
label in PHP: it must contain only alphanumeric characters and
underscores, and must start with a non-digit character or underscore.»
.... and:
«It is very important to note that the line with the closing identifier
must contain no other characters, except possibly a semicolon (;). That
means especially that the identifier may not be indented,»
So my guess is that you indented it.
> I am actually using this to create HTML, and I found that it can be
> simply written in the PHP document outside the <?php and ?> tags. But I
> would also like to be able to use a heredoc to print to a file, and I
> don't know if that is possible in PHP. If so, I'd appreciate any ideas
> on how to do it. TIA.
Heredoc is only a syntax to create a string. Once you have a string, you
can handle it as any other string: PHP does not care how it was created.
http://es2.php.net/manual/en/book.filesystem.php
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
|