Forum Moderators: coopster

Message Too Old, No Replies

Escape quotes in large blocks of text/html

Is there a way around it?

         

Donboy

9:54 pm on Mar 28, 2003 (gmt 0)

10+ Year Member



I know in Perl there are many ways to avoid having to escape quotes...

You can do this...

$Variable = qq(whatever I "want" to put);

I can also do something like this...

print <<EOF;

A whole lot of text...

EOF

So here's my question... can I do something like this in PHP? I've got a couple of books on PHP but they don't discuss this, or maybe I'm looking in the wrong place.

DrDoc

9:59 pm on Mar 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do something like this:

echo <<<X

...

X;

andreasfriedrich

10:05 pm on Mar 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, PHP [php.net] does support heredoc [php.net] syntax just like Perl [perl.com] does. It is lightly different though in that it always behaves like double quotes whereas in Perl [perl.com] you can enclose the END_MARKER in single quotes to prevent variable interpolation. The syntax is slightly different, too: Three <<< signs and the ; follows at the end of the string.

Andreas

DrDoc

10:06 pm on Mar 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Take a look at the PHP manual: Strings and the heredoc syntax [php.net]

Donboy

11:19 pm on Mar 28, 2003 (gmt 0)

10+ Year Member



Most excellent! Thanks fellas. I had no idea they had this ability, but I really figured they would. I mean, what language would be complete without it?

My intent is to convert my entire site over to PHP. Currently my whole site is designed around CGI/Perl and that's what I know best. But I'm hearing that PHP is faster and more efficient and coding the same stuff is much easier, especially with forms... and my site is very forms-heavy, so I feel like this will be a much better way to go.

Any advice for a guy who is going from Perl/CGI to PHP? I've got the books from PeachPit (the quickstart guides) and they are excellent for learning the differences. Mainly I'm looking for major differences between the two that I should know about. I'm already seeing a major difference in how arrays and hashes are handled, but I think I can rewrite this into PHP without too much trouble.

Thanks again for the help!

andreasfriedrich

9:20 am on Mar 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If all you are interested in is saving the forking of a new process via CGI you might want to consider using mod__perl which has all the advantages of running as an Apache [httpd.apache.org] module like mod_php does (speed and efficiency), complete access to the Apache [httpd.apache.org] API which mod_php does not offer and the power of a great programming language.

Andreas