Hack Forums
[PHP] [SOLVED]Double quotes in double quotes in single quotes[SOLVED] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] [SOLVED]Double quotes in double quotes in single quotes[SOLVED] (/showthread.php?tid=3742247)



[SOLVED]Double quotes in double quotes in single quotes[SOLVED] - SIM-1456245 - Sep 8, 2013

I have a little problem here, I'm trying to call a function with a parameter onclick on an echoed button in php. A bit complicated, but look at this:

PHP Code

<?php 
<script>
    function 
say(value){
        
alert(value);
    }
</
script>
<?
php
    
echo'<button onclick="say('test')">Say Test</button>'
?>


This is solved, close the thread.


* - 1n9i9c7om - Sep 8, 2013

Just escape the quotes with a backslash:

PHP Code

<?php 
<script>
    function 
say(value){
        
alert(value);
    }
</
script>
<?
php
    
echo'<button onclick="say(\'test\')">Say Test</button>'
?>



* - Ghetto~~ - Sep 8, 2013

PHP Code

<?php 
<script>
    function 
say(value){
  
alert(value);
    }
</
script>
<?
php
    
echo'<button onclick="say(\'test\')">Say Test</button>'
?>

Escape them with a backslash (\)


* - SIM-1456245 - Sep 8, 2013

Ups thanks man, what a quickie. Thanks again, close the thread, solved.