连接变量链接php


concatenate variable in link php

我想把url中的$today变量和0530&(印度标准时间)字符串连接起来。链接后的url应该是这样的http://example.com/check?image=true&id=Thu Oct 20 2016 19:29:17 GMT+0530 (India Standard Time)。束缚了自己,却依然面对着问题。有人能帮忙吗?谢谢你

<? php
$today = date("D M j Y G:i:s T ");    
 
    echo < img src = '"http://example.com/check?image=true&id=" .$today. "0530&(India Standard Time)"' />
?>

试试这个:

echo '<img src="http://example.com/check?image=true&id=' . $today . '0530&(India Standard Time)" />';

不能使用&在URL中,它是保留字符。您需要使用urlencode和urldecode函数来完成此操作。

<?php
$today = urlencode(date("D M j Y G:i:s T") . "0530&(India Standard Time)");
echo '<img src="http://example.com/check?image=true&id=' .$today .' />';
echo 'To Decode: ' . urldecode($today);
?>

这将输出

<img src="http://example.com/check?image=true&id=Thu+Oct+20+2016+16%3A15%3A02+CEST0530%26%28India+Standard+Time%29 />To Decode: Thu Oct 20 2016 16:15:02 CEST0530&(India Standard Time)