How do I make these php variables appear with single quotes? [duplicate]

1

I'm trying to make these php instructions with embedded html appear with single quotes.

This is the code:

echo '<li aria-expanded = "true" id = "'.$caption.'  "onClick ="toggle(submenu'.''.$contador_submenus.', '.$caption.')
        ">';

What I want to achieve, is that the variables of the toggle function appear when the html is loaded with single quotes

submenu'.''.$contador_submenus.', '.$caption.'

This is the result when the page loads and I need submenu1 and PROOFS ... to appear with single quotes like 'submenu1' and 'PROOF ...'

<li aria-expanded="true" id="PRUEBAS... 
     " onclick="toggle(submenu1, PRUEBAS...)
                "><a href="#"><i class="fa fa-gift fa-lg"></i> PRUEBAS... <span class="arrow"></span></a></li>

thanks.

    
asked by Javr 11.09.2017 в 12:51
source

1 answer

1

Try escaping the quotes.

$contador_submenus=1;
$caption="AAA";
echo "<li aria-expanded = \"true\" id = \"".$caption."\" onClick =\"toggle('submenu".$contador_submenus."','".$caption."')\">AAA</li>"; 
echo '<li aria-expanded = "true" id = "$caption" onClick ="toggle(\'submenu'.$contador_submenus.'\',\''.$caption.'\')>AAA</li>';    
    
answered by 11.09.2017 в 13:00