Click here to get back home

question about heredoc strings

 HomeNewsGroups | Search

comp.lang.php - PHP programming language discussions 

get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
question about heredoc strings someusernamehere 08-01-2008
Posted by someusernamehere on August 1, 2008, 12:03 pm
Please log in for more thread options
hi, I have some heredoc on this way:

$foo = <<<bar
show/hide quoted text
............................................................................
HTML code here..............................................
.....................................................................
$lang = mysql_query("SELECT * FROM lang where selected != '*'");
...................................................................
more PHP consults to mysql here
......................................................
bar;


The question is how to escape the php code for display into HTML, what
I have done
show/hide quoted text
source code I can see
all the php code commented here, and obviously is insecure for the
system, anyone know what
to do?


thanks

Posted by =?iso-8859-1?Q?=C1lvaro?= G. V on August 1, 2008, 12:09 pm
Please log in for more thread options
*** someusernamehere escribió/wrote (Fri, 1 Aug 2008 09:03:15 -0700 (PDT)):
show/hide quoted text

show/hide quoted text

Heredoc syntax is similar to double quotes: you get variables replaced with
their values, but that's all. You can't put PHP code inside.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--

Posted by Jeff on August 1, 2008, 1:45 pm
Please log in for more thread options
Álvaro G. Vicario wrote:
show/hide quoted text


Is there a way to do this:

function getSomething(){
        return 'something';
}

$content = <<<MY_BLOCK

Insert the return for a function like: getSomething()

...

MY_BLOCK;

That's doable in perl with a trick and I suspect there is a way to do it
in php.

As for the ops question, I have no idea why you'd want to insert code
in the heredoc as you can assemble heredocs just like any variable.

$content .= <<MY_BLOCK

...

MY_BLOCK;

some code...

$content .= <<MY_BLOCK

...

MY_BLOCK;

Jeff
show/hide quoted text

Similar ThreadsPosted
question about HEREDOC March 15, 2005, 11:46 am
PHP Environment strings and security question May 12, 2005, 11:48 am
Question on using "strcmp" to compare unicode strings September 15, 2004, 5:41 pm
using heredoc for SQL statements January 16, 2006, 7:27 pm
constants in heredoc December 29, 2008, 12:12 pm
Getting a function result while in heredoc December 19, 2006, 11:15 am
inclosed variable heredoc December 19, 2006, 5:06 pm
HEREDOC help, going quietly nuts October 20, 2007, 11:44 am
heredoc and array problems July 17, 2008, 2:05 pm
count newlines in heredoc variable July 30, 2008, 2:21 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Driving a better car - Fuelzilla.com

Cabling site for homeowners and pros alike - Cabling-Design.com

Friends:

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap
Privacy Policy