2013-07-16 24 views
-3

我奮力在這行代碼:

echo "<a href='"$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . $_SERVER["QUERY_STRING"] . $sign . img=$img . &shift=1'> -> </a>";

如何處理引號吧?

我的第二個問題: 我該如何將$_SERVER["QUERY_STRING"]作爲個人決定?我可以把一個if else放入字符串嗎?我的意思是我只想添加查詢字符串,如果有的話。 還是有一個完全不同的方法來達到綁定的地址?

乾杯!

回答

2

可如果行

echo "<a href='http://".$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . (trim($_SERVER["QUERY_STRING"]) == ""?$_SERVER["QUERY_STRING"]."&":"?") . "img=" . $img . "&shift=1'></a>"; 
+0

酷,看起來非常好。我得到一個'分析錯誤:語法錯誤,但意外的'&''雖然。 :( – baustellenServer

+0

@baustellenServer修復瞭解析錯誤 – Orangepill

+0

這也理論上沒有解析錯誤,但結果是'http:// localhost/instagram/index.php&img = 0&shift = 1'。:) – baustellenServer

0
$base_url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http"); 
$base_url .= "://".$_SERVER['HTTP_HOST']; 
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']); 

以上是一種方式來獲得BASE_URL使用三元。

然後,你可以寫:

echo '<a href="' . $base_url . '/'. $_SERVER['REQUEST_URI'] . (isset($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING'].'&' : '?') . 'img="' . $img . '&shift=1"></a>'; 
+0

謝謝,看起來很棒。我得到一個'解析錯誤:語法錯誤,意外的';''雖然。 :( – baustellenServer

+1

@baustellenServer現在應該工作嗎? – YahyaE

+0

理論上它沒有解析錯誤,但結果是'http:// localhost/instagram /// instagram/index.php&img =' – baustellenServer

相關問題