Question

I am trying to make a link only display on a certain page, simple right? Well, that link has an ID hash/ jQuery selector in it. Here's the code in question:

<?php if ($section == "home" ){ echo "<a data-toggle="modal" data-target="#adminlogin" target="_blank">Administration <img src="img/cog.png"></a><img src="">"; ?>

Once it gets to the "#" the code comments it's self. Is there any way I can work around this? Thanks.

Was it helpful?

Solution

You've misdiagnosed the problem.

echo "<a data-toggle="
     ^               ^
     ^               end of PHP string
     start of PHP string

You need to escape your " characters as \" when they are inside a string delimited by those characters.

Alternatively, use single quotes.

Alternatively, avoid stuffing HTML in PHP strings.

<?php
  if ($section == "home" ){ 
?>
    <a data-toggle="modal" data-target="#adminlogin" target="_blank">
      Administration 
      <img src="img/cog.png">
    </a>
    <img src="">
<?php
  }
?>

OTHER TIPS

Use ' single quotes while specifying values for html attributes,

echo "<a data-toggle='modal' data-target='#adminlogin' target='_blank'>Administration <img src='img/cog.png'></a><img src=''>";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top