Solved

elseif in heredoc

Posted on 2016-09-06
3
24 Views
Last Modified: 2016-10-08
I have just been introduced to the heredoc method and am getting into it slowly.

I figured I could use conditional statements inside the heredoc syntax but Im running into some roadblocks - (mainly my lack of knowledge)

What Im trying to do is create a hr from an array - I can get the color and the style but when it comes to showing the result, I'm falling short.

If I run this by itself it works fine - it uses a checkbox called dashed_dashed_use and if its checked it runs this, and all is well - however. Im trying to use a ifelse statement inside to simply show a
if the checkbox is not "checked".
   // START HEREDOC OUTPUT STRING
     $output = <<< START

   START;
    // IF Yes Box HAS CONTENT - ADD TO OUTPUT
    // ELSE IGNORE
    if (!empty($dashed_dashed_use)) {
      $output .= <<< DD1
        <hr style="border: 2px dashed; color:{$dashed_dashed};" data-dashed_dashed="{$dashed_dashed}">
    DD1;
    }

    // ADD CLOSING TAGS TO OUTPUT
       $output .= <<< OUTPUT_FINAL
     OUTPUT_FINAL;
    return $output;
    }

Open in new window

I cant just have a hr after the START as it will always show. So I need it so that it's a regular hr unless DD1 has been activated by the checkbox - (there are more varieties of the same, but I figured I would be able to replicate a single working version and just change the names of the $ fields.

Is this pretty straightforward, or do I need to code copies for every instance of hr I have.
0
Comment
Question by:Daryl Isaacs
  • 2
3 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points (awarded by participants)
ID: 41787123
use conditional statements inside the heredoc
Nope, doesn't work that way.  HEREDOC is just a string definition and has no conditional aspects at all.  A good way to handle the conditions is to set the variables outside the HEREDOC and then use the variables inside the HEREDOC to construct the string.
1
 

Author Comment

by:Daryl Isaacs
ID: 41787133
OK ill give it a whirl
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41834879
HEREDOC does not include conditional statements, only variable substitution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tags from access to excel 3 28
what is best version of php to use 6 44
would like the bottom of this page to be smaller 3 16
Put shading on half of picture 8 23
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now