Japar S Japar S - 2 years ago 143
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download