Beschreibung:<...">

Use img source with php variable?

I have the following code in my detailansicht.php:

<div class="file_description_box">
    <b>Beschreibung:</b><br /><br />
        <?php 
             if(!empty($beschreibung))
                 echo '<div align="center">';
                 echo '<img src="$coverlink" alt="Cover">';
                 echo '</div><br />';
                 echo format_content($beschreibung); 
             **else**
             echo '<i>Keine Beschreibung vorhanden</i>';
        ?>
</div>

but I think there should be an error in the img tag. every time I open the page, it shows me an error: "Syntax error: syntax error, unexpected T_ELSE in bla / bla / include / detailansicht.php on line 123" (line 123 is the highlight in bold). I tried several methods, but always get this error. It would be nice if someone helped me with this.

-sTarbuZz

+3
source share
8 answers

You are missing curly braces and your PHP variable was not inline. Your code should look like this:

<div class="file_description_box">
    <b>Beschreibung:</b><br /><br />
        <?php 
             if(!empty($beschreibung)){
                 echo '<div align="center">';
                 echo '<img src="'.$coverlink.'" alt="Cover">';
                 echo '</div><br />';
                 echo format_content($beschreibung); 
             }else{
                 echo '<i>Keine Beschreibung vorhanden</i>';
                }
        ?>
</div>

, , PHP, , , , , HTML, , .

PHP, , .

+15

:

if () {
...
} else {
...
}

PHP PHP.

+1

:

<?php 
     if(!empty($beschreibung)) {
         echo '<div align="center">';
         echo '<img src="$coverlink" alt="Cover">';
         echo '</div><br />';
         echo format_content($beschreibung); 
      } else {
         echo '<i>Keine Beschreibung vorhanden</i>';
      }
?>
+1

echo '<img src="', $coverlink', " alt="Cover">';

PHP-

+1

, . .

img (/" > ), .

+1

, html:

<? if(!empty($beschreibung)) : ?>
    <div align="center">
        <img src="<?= $coverlink; ?>" alt="Cover">
    </div><br />
    <?= format_content($beschreibung); ?> 
<? else : ?>
    <i>Keine Beschreibung vorhanden</i>
<? endif ; ?>

PS: , , .

: ​​ (; endif :)

+1
<?php 
     if(!empty($beschreibung)) {
         echo "<div align=\"center\">";
         echo "<img src=\"$coverlink\" alt=\"Cover\">";
         echo "</div><br />";
         echo format_content($beschreibung); 
      } else {
         echo "<i>Keine Beschreibung vorhanden</i>";
      }
?>
+1

... ...

... , ... script ( ), , $beschreibung , , php if else, ...

+1
source

Source: https://habr.com/ru/post/1708553/


All Articles