ThemeForest

PHP Help

181 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Mexico
  • Has been a member for 3-4 years
  • Bought between 50 and 99 items
  • Referred between 10 and 49 users
MCStudios says

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 :)

2354 posts
  • Grew a moustache for the Envato Movember competition
  • Community Moderator
  • Elite Author
  • Contributed a Blog Post
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Has been a member for 4-5 years
+8 more
dtbaker moderator says

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>';
?>

1 post
  • Has been a member for 2-3 years
rhussain says

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!

181 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Mexico
  • Has been a member for 3-4 years
  • Bought between 50 and 99 items
  • Referred between 10 and 49 users
MCStudios says

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 :)

181 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Mexico
  • Has been a member for 3-4 years
  • Bought between 50 and 99 items
  • Referred between 10 and 49 users
MCStudios says

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 :)

1382 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 10 and 49 users
  • Serbia
wpCanyonThemes says
$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.

by
by
by
by
by