简体   繁体   中英

Quotes/Double Quotes within PHP/MySql

This is the piece of code I am currently working with:

$outputDisplay .= '<div class="col-md-3">
                      <p class="launch">Mission: '.$mission.'</p>';

//If there are mission details, they will be displayed here
if (!$details){
    $outputDisplay .= "";
}
else{
    $outputDisplay .= '<a href="'.$details.'"target="_blank">Mission Details</a>';
}
//Closes out mission/details section
$outputDisplay .= '</div>';

I am building a row and here is what I am trying to accomplish. It will display data from $mission regardless, there will always be information there. However, there are not always websites that are associated with missions, represented by $details . $details is a website address or nothing at all.

In short, if there is information there, I want it to be represented as a link. I think I am getting backwards with the various quotes and double quotes. Any help would be great for a beginner like me.

Just use a HEREDOC , which eliminates having to worry about quotes at the PHP level:

if ($details) {
    $outputDisplay .= <<<EOL
<a href="{$outputDisplay}" target="_blank">Mission Details</a>
EOL;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM