Chiwda
Chiwda

Reputation: 1344

Single/Double quotes messing up PHP/HTML

I have some inherited some code and I am trying to make some simple changes, but the quote marks are tripping me up. Here is the original code:

<a href='<?php echo SITE_URL.'members-search.html';?>' class='btn btn-large<?php if($curPage == "Filters") echo " btn-primary";?>'><i class="icon-magnet<?php if($curPage == "Filters") echo " icon-white";?>"></i> Members</a>

I want to use some variables instead of the hard coded menu items, so I made a simple change:

<a href='<?php echo SITE_URL.'members-search.html';?>' class='btn btn-large<?php if($curPage == "Filters") echo " btn-primary";?>'><i class="icon-magnet<?php if($curPage == "Filters") echo " icon-white";?>"></i> <?php $menuitem1 ;?></a>

And the pages just gets munged beyond recognition. I have tried various things, until I got some success (in some places), by removing all quotes from the HTML. For example:

<a href=<?php echo SITE_URL.'members-search.html';?> class=btn btn-large<?php if($curPage == "Filters") echo " btn-primary";?>><i class="icon-magnet<?php if($curPage == "Filters") echo " icon-white";?>"></i> <?php $menuitem1 ;?></a>

But this doesn't work consistently. What am I doing wrong? Where should I use double quotes and where single? This was to be a half-hour job and it has consumed an entire day! Please help...

Upvotes: 0

Views: 461

Answers (3)

Nagesh Tiwari
Nagesh Tiwari

Reputation: 3

I don't see any quote related issue! Like bloodyKnuckles mentioned you forgot to use echo before $menuitem1.

This is working:

<a href="<?php echo SITE_URL.'members-search.html'; ?>" class="btn btn-large<?php if($curPage == 'Filters') echo ' btn-primary'; ?>"><i class="icon-magnet<?php if($curPage == 'Filters') echo ' icon-white';?>"></i> <?php echo $menuitem1; ?></a>

Upvotes: 0

NaijaProgrammer
NaijaProgrammer

Reputation: 2957

Try this:

<a href="<?php echo SITE_URL;?>members-search.html" class="btn btn-large<?php if($curPage == 'Filters') echo ' btn-primary';?>"><i class="icon-magnet<?php if($curPage == 'Filters') echo ' icon-white';?>"></i> Members</a>

Upvotes: 0

Albzi
Albzi

Reputation: 15609

You're using ''s inside of the href starting with ', and "'s inside of the i class! You need to either use single quotes inside of double or double in single, or just use \"/\' every time you want to use a single/double quote inside of quotes.

You can do this:

<a href="<?php echo SITE_URL.'members-search.html';?>" class="btn btn-large<?php if($curPage == 'Filters') echo ' btn-primary';?>"><i class="icon-magnet<?php if($curPage == 'Filters') echo ' icon-white';?>"></i> Members</a>

Upvotes: 1

Related Questions