Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have to echo the below statement but it has many quotations within quotations, I tried below using \" but the confirm msg is not working, which means quotations have errors.

Please help.

The below fixed my problem:

PHP
$msg = "'Any message'";
echo '<a href="'. base_url() .'/Students/delsection/'.$row->id.'" class= "btn btn-sm btn-danger" onclick=" return confirm('.$msg. ');">Delete</a>


What I have tried:

PHP
echo '<a href="'. base_url() .'/Students/delsection/'.$row->id.'" class= "btn btn-sm btn-danger" onclick= \" return confirm("Are you sure you want to delete this Section?");\" >Delete</a></td>
Posted
Updated 10-Nov-20 19:34pm
v2

1 solution

You need to use backslash (\) as escape sequence for double quotes in PHP

I tested this and it works:
PHP
echo "<td><a class = 'btn btn-sm btn-danger' href='some-url.php?ID=3' onclick='return confirm(\"Are you sure to delete?\")'> Delete </a></td> \n";
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900