Solved

How to display a functions data inside HEREDOC

Posted on 2016-11-27
2
54 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 350 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 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 150 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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 …

752 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