2017-08-09 110 views
-3

我有一個圖像懸停在PHP頁面上,該圖像應鏈接到某個URL。PHP鏈接無法正常工作

if(file_exists($actionsloaded)) 
    echo '<a href=\"index.php\"><img src="/wp-content/uploads/2017/07/'.$image_on.'" onmouseover="this.src=\'/wp-content/uploads/2017/07/'.$image_off.'\';" onmouseout="this.src=\'/wp-content/uploads/2017/07/'.$image_on.'\';"/></a>'; 
else 

問題是,當我點擊它進入url.com/"index.php/"

任何想法的鏈接可能是什麼錯呢?

+4

不要逃避 –

+1

你不需要逃避引號'href' –

回答

2

刪除\ on href。我已經解決了,你可以用這個代碼

echo '<a href="index.php\"><img src="/wp-content/uploads/2017/07/'.$image_on.'" onmouseover="this.src=\'/wp-content/uploads/2017/07/'.$image_off.'\';" onmouseout="this.src=\'/wp-content/uploads/2017/07/'.$image_on.'\';"/>asdf</a>' 

如果$image_on=10;$image_off =20;那麼這段代碼顯示在瀏覽器

<body><a href="index.php\"><img src="/wp-content/uploads/2017/07/10" onmouseover="this.src='/wp-content/uploads/2017/07/20';" onmouseout="this.src='/wp-content/uploads/2017/07/10';">asdf</a></body> 
+0

有沒有'/''中href',我想你的意思'\'。你離開了第二個。 – Barmar

+0

@Barmar感謝您的更正 –

1

您shuld刪除所有報價逃生,看看下面更新的代碼。

if(file_exists($actionsloaded)) 
    echo '<a href="index.php"><img src="/wp-content/uploads/2017/07/'.$image_on.'" onmouseover="this.src='/wp-content/uploads/2017/07/'.$image_off.'';" onmouseout="this.src='/wp-content/uploads/2017/07/'.$image_on.'';"/></a>'; 
else 
+0

非常感謝您,那就是訣竅:) – Giuliano