Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to display a functions data inside HEREDOC

Posted on 2016-11-27
2
Medium Priority
?
91 Views
Last Modified: 2016-11-27
I am populating a dropdown with database records without using HEREDOC but I now want to do it with HEREDOC. Is is possible to edit this to display the contents of the function query or not? I assume I should remove the PHP tags from inside the HEREDOC but I just left them there so you can see the actual HTML.

$showData = <<<SHOWDATA

<div class="form-group">
<label>Select Categories</label>
<select multiple data-title="Multiple Select" name="cat_name" class="selectpicker" data-style="btn-info btn-fill btn-block" data-menu-style="dropdown-blue">
<?php list_categories_multiple($link); ?>
</select>
</div>	
SHOWDATA;
echo $showData;

Open in new window

0
Comment
Question by:Black Sulfur
2 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 1400 total points
ID: 41903013
You can't: HEREDOC manages only variables. But you can do this:
$showData = <<<SHOWDATA
<div class="form-group">
<label>Select Categories</label>
<select multiple data-title="Multiple Select" name="cat_name" class="selectpicker" data-style="btn-info btn-fill btn-block" data-menu-style="dropdown-blue">
SHOWDATA;
$showData .= list_categories_multiple($link);
$showData .= <<<SHOWDATA
</select>
</div>	
SHOWDATA;
echo $showData;

Open in new window

1
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 600 total points
ID: 41903027
A smart design would create all of your variables in a PHP object instance of StdClass or your own preferred object, and then inject the variables into the HTML via the HEREDOC.  If you have a function that creates HTML statements and you need these injected into the output HTML document, you might want to consider redesigning the application using a Separation of Concerns.

A HEREDOC is just another way of writing a string variable as if you had double quotes.  
http://php.net/manual/en/language.types.string.php
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question