Japar S Japar S - 5 months ago 6x
PHP Question

Semicolon in echo php

i have code like this :

echo '<a onclick="function(''.$some.'');">';

how can it return html like this :

<a onclick="function('some');">

Big Thanks


Since you quoted the string with single quotes, you have to escape them inside the string.

Simply add a backslash \ before each single quote inside the string:

    echo '<a onclick="function(\''.$some.'\');"';

Also you can do that in a few other ways like:

echo "<a onclick=\"function('{$some}');\""; 

Double quotes lets you simply embed a variable instead of concating, but now you have to escape double quotes.