473,624 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting a function result while in heredoc

Thanks to those that taught me to use heredoc to embed html in
php. I don't want to start the html in php vs php in html
discussion again.,

heredoc works a treat for that which I am doing except:
In the generated html I have a number of checkboxes. I fill
in the checkboxes from a boolean value in a mySQL table. To make
this easier I use a function that takes the boolean and return
either 'checked' or ''. This worked well when I was
concatenating the html into a variable rather than using heredoc,
but it was really messy.

Short, simple question: is there anyway to get php to evaluate a
function while in a heredoc block ?

I know I could assign the results of using the function to
variables outside of the heredoc block or I could break the block
for the function, but the first is cumbersome and the second gets
rid of the clarity of the heredoc approach.

bill
Dec 19 '06 #1
6 6242

bill wrote:
Thanks to those that taught me to use heredoc to embed html in
php. I don't want to start the html in php vs php in html
discussion again.,

heredoc works a treat for that which I am doing except:
In the generated html I have a number of checkboxes. I fill
in the checkboxes from a boolean value in a mySQL table. To make
this easier I use a function that takes the boolean and return
either 'checked' or ''. This worked well when I was
concatenating the html into a variable rather than using heredoc,
but it was really messy.

Short, simple question: is there anyway to get php to evaluate a
function while in a heredoc block ?
You can't do this with any string syntax.
>
I know I could assign the results of using the function to
variables outside of the heredoc block or I could break the block
for the function, but the first is cumbersome and the second gets
rid of the clarity of the heredoc approach.
I'm afraid this is the only way. Maybe fill an array with the return of
functions?
>
bill
Dec 20 '06 #2
Rik
bill wrote:
Thanks to those that taught me to use heredoc to embed html in
php. I don't want to start the html in php vs php in html
discussion again.,

heredoc works a treat for that which I am doing except:
In the generated html I have a number of checkboxes. I fill
in the checkboxes from a boolean value in a mySQL table. To make
this easier I use a function that takes the boolean and return
either 'checked' or ''. This worked well when I was
concatenating the html into a variable rather than using heredoc,
but it was really messy.

Short, simple question: is there anyway to get php to evaluate a
function while in a heredoc block ?
You'd be right back where you started from, php-snippets in HTML-blocks...
I know I could assign the results of using the function to
variables outside of the heredoc block or I could break the block
for the function, but the first is cumbersome and the second gets
rid of the clarity of the heredoc approach.

Possible in heredoc:
- scalar variables
- scalar array-values
- scalar object-values

Not possible in heredoc:
- functions/results
- constants

The last is a great irritation.
--
Rik Wasmus
Dec 20 '06 #3
Rik wrote:
Not possible in heredoc:
- functions/results
- constants

The last is a great irritation.
<?php
foreach (get_defined_co nstants() as $k =$v)
$CONSTANTS[$k] = $v;

print "E_USER_ERR OR is {$CONSTANTS['E_USER_ERROR']}.";
?>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Dec 20 '06 #4
Rik
Toby Inkster wrote:
Rik wrote:
>Not possible in heredoc:
- functions/results
- constants

The last is a great irritation.

<?php
foreach (get_defined_co nstants() as $k =$v)
$CONSTANTS[$k] = $v;

print "E_USER_ERR OR is {$CONSTANTS['E_USER_ERROR']}.";
Well, yeah.
The reason for using constants imho is their deployability in functions,
and the fact they never change.
$CONSTANTS will not be a superglobal, so in every function where they have
to be used in such a syntax this would be deployed, or one has to make it
global/use $GLOBALS. Not really a solution, just another workaround. I'd
like to see "{E_USER_ERROR} " work. For now, it's usually either
concatenating small strings or temporarily assign it to a variable, elas.
--
Rik Wasmus
Dec 20 '06 #5
bill wrote:
Thanks to those that taught me to use heredoc to embed html in php. I
don't want to start the html in php vs php in html discussion again.,

heredoc works a treat for that which I am doing except:
In the generated html I have a number of checkboxes. I fill in the
checkboxes from a boolean value in a mySQL table. To make this easier I
use a function that takes the boolean and return either 'checked' or
''. This worked well when I was concatenating the html into a variable
rather than using heredoc, but it was really messy.

Short, simple question: is there anyway to get php to evaluate a
function while in a heredoc block ?

I know I could assign the results of using the function to variables
outside of the heredoc block or I could break the block for the
function, but the first is cumbersome and the second gets rid of the
clarity of the heredoc approach.

bill

Thanks all, I was afraid there was not a simple way to do this.
bill
Dec 20 '06 #6
bill wrote:
[snip]
Short, simple question: is there anyway to get php to evaluate a
function while in a heredoc block ?
[snip]
Rik replied:
[snip]
Possible in heredoc:
- scalar variables
- scalar array-values
- scalar object-values

Not possible in heredoc:
- functions/results
- constants

The last is a great irritation.
[snip]

Indeed. But since you can use object values, you can overload a helper
class using the __get overload. So instead of something like:

echo <<<EOT
<input type="checkbox" name="$name"{ge t_checked_text( $id)}>
EOT;

which unfortunately doesn't work, you could do something like:

echo <<<EOT
<input type="checkbox" name="$name"{$c hecked->$id}>
EOT;

This might be overkill for your needs but it has worked well for me in
the past. Good luck.

J

Dec 22 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2579
by: James | last post by:
Please help - getting very desperate! Sun, 12 October 2003 05:39 I have PHPDEV 4.2.3 from Firepages.com.au as the upgrade to 4.3.0 did not work. I also had an abortive download from PHP.NET as I could not configure Apache myself. The REAL problem is that PHPmyAdmin works and sees my test database Wines.... But my PHP program does not!
7
11448
by: flupke | last post by:
Hi, i have php script where i use a heredoc type of variabele to print out some html. In the heredoc, i use the values of several other vars. php snippet: $div=<<<END_DIV <DIV class="linkblock">
3
2072
by: tshad | last post by:
I have a page that I am getting a username and password as a random number (2 letters, one number and 4 more letters) I have 2 functions I call: ************************************************* Function RandomString(size as integer, lowerCase as boolean) as string Dim builder as StringBuilder = new StringBuilder() Dim random as Random = new Random() Dim i as integer dim ch as char
2
2151
by: Matt F | last post by:
I can't seem to get heredoc to populate correctly with variables through a form. <textarea name="Template" rows="10" cols="80">Template Here</textarea> Contents could be something like: I want to replace $myarray and another variable $myarray I call heredoc this way:
0
1012
by: Heshan Suri | last post by:
Hi, I have written a the following python code to analyse a function or a method. I am having a script which is having a python function (add) and a class (MyClass) with a method (multiply).When I analyse it using the following method(analyze_func) , I get an output like below. The problem I am having is, I need to get the value 'MyClass.multiply' from the obj. When I do obj.__name__ , I am only getting "multiply" only.So can anyone...
7
5563
by: Jeff | last post by:
I have this: $content = <<<TD $D TD; that fails silently and stops php even though errors are turned on
2
1647
by: Adam Cantrell | last post by:
How could I count the number of newlines in a heredoc variable? This outputs 0, but I thought heredoc preserved newlines? <? $test = <<<END <a href="test5.php">adam</a> <p> Hi There </p> END;
2
1385
by: someusernamehere | last post by:
hi, I have some heredoc on this way: $foo = <<<bar <form action="index.php" method="POST" name="user"> ............................................................................. HTML code here.............................................. ...................................................................... $lang = mysql_query("SELECT * FROM lang where selected != '*'");...
2
2309
by: ziycon | last post by:
I have a site that has been using the HEREDOC syntax for awhile, after a recent upgrade to the site a lot of pages are erroring with the below error, i can't figure it out at ll, any ideas? All the pages are giving the same error on different lines but it seems to be related to the HEREDOC syntx?
0
8238
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1485
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.