PHP链接无法正常工作

问题描述:

我有一个图像悬停在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' –

删除\ 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感谢您的更正 –

您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