HTML/PHP: How can we insert PHP variable into anchor tag of html? -
i have .php page has lot of html parts in it. running loop , each value in loop, want pass php variable in anchor tag inside loop.
i have tried this:
for($i =0; $i<5 ; $i++) { <a href = "test.html?id= <?php $i ?> > sample text </a> }
but isn't working.
any number of ways. point not mix html php, keep them separately parse-able. this:
for($i =0; $i<5 ; $i++) { echo '<a href="test.html?id=' . $i . '"> sample text </a>'; }
(in example of code php, , html string that's echo
-ed output.)
or this:
for($i =0; $i<5 ; $i++) { ?> <a href="test.html?id=<?php echo $i; ?>"> sample text </a> <?php }
(in example php code wrapped in <?php ?>
tags , html kept outside tags.)
as long keep php code in <?php ?>
tags , html out of tags, parsers know difference.
Comments
Post a Comment