javascript - PHP echo return confirm function slashes - Stack Overflow

Hi i have been using this php echo statement echo "<a href = 'message_delete_script_outbox

Hi i have been using this php echo statement

echo "<a href = 'message_delete_script_outbox.php?id=".$row['id']."'"."onclick='return        
confirm(/Are you sure, you want to delete?/)'>Delete</a>";

The statement is working i am seeing this message /Are you sure, you want to delete?/ instead of this Are you sure, you want to delete?

Hi i have been using this php echo statement

echo "<a href = 'message_delete_script_outbox.php?id=".$row['id']."'"."onclick='return        
confirm(/Are you sure, you want to delete?/)'>Delete</a>";

The statement is working i am seeing this message /Are you sure, you want to delete?/ instead of this Are you sure, you want to delete?

Share Improve this question edited Sep 7, 2012 at 11:49 j0k 22.8k28 gold badges81 silver badges90 bronze badges asked Sep 7, 2012 at 11:08 h_hh_h 1,2314 gold badges28 silver badges47 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

Your quote nesting is a little messed up. Try to follow these rules:

  • Outer quote = " (This marks the beginning and end of the string)
  • Inner quote = \" (Escaped as to not flag "beginning/end of string")
  • Third-tier quote = ' (Literal quote)
  • Fourth-tier quote = \' (Literal quote that will be generated as an escaped outer quote)

Result:

echo "<a href=\"message_delete_script_outbox.php?id=".$row['id']."\"onclick=
      \"return confirm('Are you sure, you want to delete?')\">Delete</a>";

More info about quote nesting: http://blog.opensourceopportunities./2007/10/nested-nested-quotes.html

You enclose the message in quotes, and those quotes need to be escaped to avoid confusing the PHP script:

echo "<a href = 'message_delete_script_outbox.php?id=".$row['id']."'"."onclick='return        
confirm(\"Are you sure, you want to delete?\")'>Delete</a>";

Just add double quotes and escape them

echo "<a href = 'message_delete_script_outbox.php?id=".$row['id']."' onclick='return confirm(\"Are you sure, you want to delete?\")'>Delete</a>";

I am not sure if you added a new line when you posted here, but you should know you cannot have that script on 2 lines.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744166621a4561334.html

相关推荐

  • javascript - PHP echo return confirm function slashes - Stack Overflow

    Hi i have been using this php echo statement echo "<a href = 'message_delete_script_outbox

    9天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信