2016-06-03 2 views
-1

Ich bin mir bewusst, dass ich kein Echo in einem Echo verwenden kann. Mein PHP Code ist:Php echo url innerhalb eines Echos

echo '<img src="img/image1.jpg" 

Ich möchte PHP-Variable als Quelle verwenden. Some wie:

echo '<img src="php-code" 
+2

'echo" Thamilan

+3

Do try to learn basic php before asking on SO. – Epodax

+0

@Epodax Be a bit supportive. He is obviously in the very basics of scripting and it could be tough to formulate Google queries and find correct place to look for such a thing. –

Antwort

1

Verwendung (dot) Sie PHP-Variable in echo-Anweisung verketten kann..

echo '<img src="'.$src.'" />'; 
+0

Warum Verkettung ist in diesem Fall erforderlich ?? –

+0

Da Sie "einfache Anführungszeichen" verwenden, werden Variablen zwischen "einfachen Anführungszeichen" nicht als solche interpretiert – DarkBee

+0

http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double -quoted-strings-in-php – DarkBee

1

Sie haben vier Möglichkeiten:

$url = '...'; 

//1 
echo '<img src="' . $url . '">'; 

//2 
echo "<img src='{$url}'>";  //Note that you have to use double quotes 

//3 
echo '<img src="'; 
echo $url; 
echo '">'; 

//4 
echo '<img src="', $url, '">'; //I would not recommend this one though 
0

nur erstes Echo überspringen und die html mit einem Echo in der Mitte

<img src="<?=$src?>"> 
0

All diese Werke

echo '<img src="', $url, '">'; # This works by sending 3 different parameters to echo 
echo '<img src="' . $url . '">'; # This works by concatenating 3 strings before echoing 

echo '<img src="'; echo $url; echo '">'; # This works by echoing 3 strings in turn 

echo "<img src=\"$url\">"; # All of these works by inserting 
echo "<img src=\"${url}\">"; # the value of $url in the string 
echo "<img src=\"{$url}\">"; # before echoing. " needs to be escaped. 

# And finally, this (called HEREDOC) does the same thing as above 
# only without ", so that sign is not needed to be escaped 
echo <<<FOO 
    <img src="$url"> 
    <img src="{$url}"> 
    <img src="${url}"> 
FOO; 
0
schreiben

Es gibt viele Lösungen. Ich bevorzuge diese: <?php echo '<img src="'.$url.'">'; ?> $ url steht für die Image-URL, ich denke du weißt es ist.

Sie können es auch: Zum Beispiel: <img src="<?php echo $url; ?>"> Aber Ich mag die erste Methode, ist es eine einfache Möglichkeit Strings zu löschen.