Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add some php function inside html content

Tags:

html

php

is it possible to do some function inside html content ?

here my code :

$parts = explode(',', 'option 1,option 2,option 3');
echo "<div class='form-group'>
        <div class='col-sm-12'>
          <label>label</label>
          <select class='form-control' style='width: 100%;' name='select' placeholder='select'>
          foreach($parts as $index=>$key) {
              echo '<option>'.$key .'</option>';
          }
          </select>
        </div>
      </div>";
like image 959
Ibnu Habibie Avatar asked Jul 01 '26 09:07

Ibnu Habibie


1 Answers

Do this think like this way:

Depart the HTML and PHP, use the PHP tag each time when you need inside a HTML page / PHP page.

<?php
$parts = explode(',', 'option 1,option 2,option 3');
?>
<div class='form-group'>
    <div class='col-sm-12'>
        <label>label</label>
        <select class='form-control' style='width: 100%;' name='select' placeholder='select'>
        <?php
        foreach($parts as $index=>$key){
        ?>
            <option><?php echo $key;?></option>
        <?php }?>
        </select>
    </div>
</div>
like image 198
Murad Hasan Avatar answered Jul 03 '26 22:07

Murad Hasan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!