Jump to content

Problem with Quotes


doubledee

Recommended Posts

I have a block of navigation tabs that I need to place inside of PHP so I can toggle whether the tabs appear or not.

 

Here is a snippet of what I am trying to do, but it is messy and not compiling or whatever you call it...

 

<?php
	echo "<ul id='profileMenu'>
			<li id='firstTab'>" . (isset($tabName=='about-me') ? class='current' : '') . "</li>
		</ul>";
?>

 

How can I both FIX THIS and CLEAN IT UP - if that is possible?!

 

Thanks,

 

 

Debbie

 

 

 

Link to comment
Share on other sites

in your OP code:

 


<?php
	echo "<ul id='profileMenu'>
			<li id='firstTab'>" . (isset($tabName=='about-me') ? class='current' : '') . "</li>
		</ul>";
?>

 

1) Looks like your ternary is supposed to add something inside your opening "li" tag but you closed it before the ternary

 

2) isset syntax is wrong.  isset takes variables for arguments, not expressions.

 

3) Did not wrap quotes around the strings you are trying to add to the "li" tag

 

4) Did not properly wrap the ternary in parenthesis

 

Here is what the code should look like

 

<?php
	echo "<ul id='profileMenu'>
			<li id='firstTab'" . ((isset($tabName)&&$tabName=='about-me') ? " class='current'" : '') . "></li>
		</ul>";
?>

 

Couple notes/opinions/suggestions:

 

1) Issues like this won't happen if you separate your logic from your content.  Put that ternary in a variable before the echo and then include the variable in the echo.

 

2) If you want to echo things multi-line like that, you might wanna look into using heredoc syntax.  This will only really work out for you if you follow suggestion #1. 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.