hi I’m working with PHP and i have this code:
$output .= '<a href="javascript:void(0);" onclick="return remove_link(. $name .' , '. $count .')">Remove link</a>';
And this is how the output looks like:
<a href="javascript:void(0);" onclick="return remove_sidebar_link(manu , 1);">Remove link</a>
There’s only one problem with that:
onclick=”return remove_sidebar_link(manu , 1);
The name (in this case manu) should be displayed within quotes like this:
onclick=”return remove_sidebar_link(‘manu’ , 1);
But I’m not sure how to accomplish that, any help is appreciated 
- Grew a moustache for the Envato Movember competition
- Community Moderator
- Contributed a Blog Post
- Author was Featured
- Item was Featured
- Won a Competition
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Has been a member for 4-5 years
try not putting html into a php string if possible. just write the html and use php where it’s needed.
edit: sorry about the bogus code, this forum doesn’t like certain code.
some options:
<!-- your other html here -->
<a href="javascript:void(0);" onclick="return remove_sidebar_link('<?php echo $name;?>' , <?php echo $count;?>);">Remove link</a>
<!-- your other html here -->
<?php ob_start();
?>
<!-- your other html here -->
<a href="javascript:void(0);" onclick="return remove_sidebar_link('<?php echo $name;?>' , <?php echo $count;?>);">Remove link</a>
<!-- your other html here -->
<?php $output = ob_get_clean();
?>
<?php $output .= 'a href="javascript:void(0);" onclick="return remove_link(\'' . $name . '\',' . $count . ');?>Remove link /a>';
?>
Hi,
try this
$output .= '<a href="javascript:void(0);" onclick="return remove_link(\'. $name .'\' , '. $count .')">Remove link</a>';
You need to put the single quote (‘) into the output string but php will think that you intend to close the string (text) so you must put (\) in front of the single quote so php knows to output the single quote and not think that you intend to close the string. Hope this makes sense. Try it out anyway!
dtbaker said
try not putting html into a php string if possible. just write the html and use php where it’s needed. edit: sorry about the bogus code, this forum doesn’t like certain code.
Hi dtbaker
Thank you very much, that worked perfectly, just one question if i put html into a php string could that cause any problems?
Anyway thank’s again 
rhussain said
Hi,try this
$output .= '<a href="javascript:void(0);" onclick="return remove_link(\'. $name .'\' , '. $count .')">Remove link</a>';You need to put the single quote (‘) into the output string but php will think that you intend to close the string (text) so you must put (\) in front of the single quote so php knows to output the single quote and not think that you intend to close the string. Hope this makes sense. Try it out anyway!
Hi rhussain
Thank’s for the explanation, your solution also works 
$output .= '<a href="javascript:void(0);" onclick="return remove_link('."'". $name ."'".' , '. $count .')">Remove link';
Damn this code including on TF.
Just add .”’”.$name.”’”. double quotes outside, single quote inside.
