What is wrong with this php echo expression?

Sorry, I know this is the main question, but I tried for hours, and I cnt seemed to think that was not the case!

 echo '<tr><td><img src="images/$row['picture']" alt="' . $row['username'] . '" /></td>';

- A cleaner way to do this without error.

thank

+3
source share
5 answers

Here you are missing '.

I would do it like this:

 echo '<tr><td><img src="images/' . $row['picture'] . '" alt="' . $row['username'] . '" /></td>';

There are several other ways to do this, but I would not recommend using short tags or inserting variables into ever strings . It doesn't matter if it's double quotation marks, break the line and concatenate. It is much easier on the eyes and makes for cleaner code.

, , .

 echo '<tr><td><img src="images/', $row['picture'], 
      '" alt="', $row['username'], '" /></td>';
+4
 echo "<tr><td><img src='images/{$row['picture']}' alt='{$row['username']}' /></td>";

PHP.

+3
?>
<tr><td><img src="images/<?=$row['picture']?>" alt="<?=$row['username']?>" /></td>
<?
+3

' . $row[', . , echo $row['picture'] (. ), ("), .

, : ( .) PHP. Echo , :

echo '<tr><td><img src="images/', $row['picture'], '" alt="',
     $row['username'], '" /></td>';

, <?=, <?php echo:

<?= $value, ' + 1 = ', $value + 1 ?>
+2

$row ['picture']

echo '<tr><td><img src="images/' . $row['picture'] . '" alt="' . $row['username'] . '" /></td>';

, :

echo "<tr><td><img src='images/{$row['picture']}' alt='{$row['username']}'/></td>";

If you have double quotes, you can include array values ​​in a string if they are enclosed in {}. Of course, you need to change the double quotes in the html elements to single ones or to avoid them.

+1
source

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


All Articles