dotaer1993 2016-09-08 13:06 采纳率: 100%
浏览 38
已采纳

在PHP标记内使用site_url()回显图像标记

I have a loop in my view that outputs all the content gathered from the database:

<?php foreach($content as $contentRow): ?>
     <?php
          echo $contentRow->value; 
     ?>  
<?php endforeach; ?>

This works fine for HTML strings like:

<h2><strong>Example Text</strong></h2>

however I have some image content that I would like to display and I have tried the following database entries to no avail:

<img src="<?php echo site_url('pathToImage/Image.png'); ?>" alt="Cover">"
<img src="site_url('pathToImage/Image.png')" alt="Cover\">"

I feel like I am missing a step on how to use PHP values in this way.

How do I access the URL of the image and use that to show the image?


Full Code Edit

<?php
    $CI =& get_instance();
?>

<div class="container">

    <div class="row">        
        <div class="col-md-9">
            <div class="col-md-2"></div>
            <div class="col-md-20">
                <!--<form class="form-center" method="post" action="<?php echo site_url(''); ?>" role="form">-->
<!--                    <h2 class="">Title</h2>
                    <h2 class=""SubTitle/h2>-->
                    <?php echo $this->session->userdata('someValue'); ?>

                    <!--//<table class="" id="">-->

                        <?php foreach($content as $contentRow): ?>
                        <tr>
                            <td><?php
                            echo $contentRow->value; 
                            ?></td>                            
                        </tr>
                        <?php endforeach; ?>
                    <!--</table>-->

                <!--</form>-->
            </div>

            <div class="col-md-2"></div>

        </div>
    </div>

</div><!-- /.container -->

and the values are being read out in $contentRow->value;

  • 写回答

2条回答 默认 最新

  • duanlaofu4108 2016-09-08 13:12
    关注

    I have to verify this, but to me it looks like you are echo'ing a string with a PHP function. The function site_url() is not executed, but simply displayed. You can execute it by running the eval() function. But I have to add this function can be very dangerous and its use is not recommended.

    Update: To sum up some comments: The use of eval() is discouraged! You should reconsider / rethink your design. Maybe the use of tags which are replaced by HTML are a solution (Thanks to Manfred Radlwimmer). Always keep in mind to never trust the data you display, always filter and check!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?