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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -