Solved

How to display a functions data inside HEREDOC

Posted on 2016-11-27
2
42 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 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 109

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do uses indexes to maximize MySQL Searches 14 55
Uploading a CSV Data Import via PHP & MySql 3 35
Undefined variable problem 5 23
Log in through ID 5 19
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

821 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