2013-10-12 25 views
1
呼應鏈接

我想串起來的URL,然後把它呼應了鏈接語法在PHP

<?php 
$url = 'https://www.google.com/#q='.$word; 
echo '<a href="'.$url.'" id="link">' 'Google This!' '</a>'; 
?> 

敢肯定這是與行情但是我不確定如何的問題解決它們?謝謝!

回答

1
echo '<a href="'.$url.'" id="link"> Google This! </a>'; 
+1

實際上,你可以呼應個以上的字符串,如果你分開他們用逗號。 'echo'string','string','string';' – brenjt

+0

哦,是的,這是真的。感謝您指出了這一點。 –

0
echo '<a href="'.$url.'" id="link">' . 'Google This!' . '</a>'; 

OR

echo '<a href="'.$url.'" id="link">Google This!</a>'; 
1
<?php 
$url = 'https://www.google.com/#q='.urlencode($word); 
echo '<a href="'.htmlentities($url).'" id="link">Google This!</a>'; 
0

我覺得最otimized辦法做到這一點是:

<?php 
$url = 'https://www.google.com/#q='.$word; 
echo '<a href="'.$url.'" id="link">Google This!</a>'; 
?> 

您可以在有關於字符串的更多信息:http://php.net/manual/en/book.strings.php

0

首先,你不用連接就可以在你的字符串中斷。

>' 'Google This!' '</ 

應該是:

<?php 
$url = 'https://www.google.com/#q='.urlencode($word); 
echo '<a href="'.$url.'" id="link">'.'Google This!'.'</a>'; 
?> 

始終使用安全 「進行urlencode()」 爲好。 See php documentation here。它確保URL中的所有字符都是安全的。

0

個人所有的單引號和雙引號我發瘋所以只要有可能我做的PHP變量,然後呼應了一些什麼,需要在html

<?php $url = 'https://www.google.com/#q='.urlencode($word); ?> 

<a href="<?php echo $url; ?>" id="link">Google This!</a>