php echo other php code

后端 未结 2 1626
刺人心
刺人心 2021-01-28 16:26

Im trying to have php code that contains an echo. within that echo however, I need it to echo php code within it. a short example is bellow.



        
相关标签:
2条回答
  • 2021-01-28 17:02

    In a html context, <?php, <something, etc, is the opening of a html tag. Edit < with his html entity &lt; to prevent it happening..

    &lt;?php
    

    Even better, use htmlspecialchars:

    <?php echo htmlspecialchars('<?php echo "test"; ?>'); ?>
    
    0 讨论(0)
  • 2021-01-28 17:04

    Otherwise, try reversing it:

    while ($row = mysql_fetch_array($result)) 
    {
        ?>
        <div style="position: relative;" >
            <img src="Backgrounds/<?=$row[id]?>.jpg" alt="error">
            <br /><br />
            <?php
                //Some php content that also uses $row[] content
            ?>
            <br />
        </div>
        <?php
    }
    

    And also switch to PDO objects.

    0 讨论(0)
提交回复
热议问题