How to place variable concatenated inside a <a>?

Asked

Viewed 52 times

1

I have this php line:

echo '<a href="?p=ultimasnoticias&pagina='.$i.'">'.$i.'</a>';

I need to put the .$i. between the <a>.$i.</a> in my html script, example:

<nav>
  <ul>
    <li>
      <a>.$i.</a>
    </li>

How do I do that?

  • The file that contains html has the extension .html? Or is .php?

  • 1

    @Andreicoelho The extension of all files are .php. But I’ve already solved it, thank you.

2 answers

3


Easy.

<nav>
  <ul>
    <li>
      <?php echo '<a href="?p=ultimasnoticias&pagina='.$i.'">'.$i.'</a>'; ?>
    </li>

Another option would be:

<nav>
  <ul>
    <li>
        <a href="?p=ultimasnoticias&pagina=<?php echo $i; ?>"><?php echo $i; ?></a>
    </li>

I hope I’ve helped.

  • Thank you very much!

2

To decrease the code can also be:

<nav>
<ul>
<li>
   <a href="?p=ultimasnoticias&pagina=<?=$i?>"><?=$i?> 
   </a>
</li>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.