如何在php中为循环中的img标记提供源代码
我在一个表中使用了一个引导模式,在这个模式中,我想显示一个图片,它的源在一个数组中,我正在迭代并从中得到它。但图片不会显示 这是我的密码如何在php中为循环中的img标记提供源代码,php,jquery,twitter-bootstrap,Php,Jquery,Twitter Bootstrap,我在一个表中使用了一个引导模式,在这个模式中,我想显示一个图片,它的源在一个数组中,我正在迭代并从中得到它。但图片不会显示 这是我的密码 <table class='table table-hover table-responsive' width='21' id='tableHayatcomputers'> <caption>Hayat Computers</caption> <?php foreach($hayatcomputers as $hc){
<table class='table table-hover table-responsive' width='21' id='tableHayatcomputers'>
<caption>Hayat Computers</caption>
<?php foreach($hayatcomputers as $hc){ ?>
<tr>
<td><?php echo $hc['name'] ?></td>
<td><?php echo $hc['price'] ?></td>
<td><div class="container">
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
Details
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<img src="<?php preg_replace('/\s+/', '%20',$hc['image'])?>" class="img-thumbnail" alt="Cinque Terre" width="304" height="236"></img>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php } ?>
</table>
需要回显
preg_replace
。我也是
<?php echo preg_replace('/\s+/', '%20',$hc['image']);?>
或
回显结果
或
OMG!!!天啊!!!天哪!!!!!!!!!!!!!!!!!所有这些技能都化为乌有!!!当你连续8小时编写代码时,就会发生这种情况!!!今天的节目已经够多了!谢谢大家等等,为什么图像源没有迭代?我的意思是每一行都应该有不同的图像,对吗?不知道,$hayatcomputers
看起来像什么?数组([0]=>name=>abc,image=>adad,price=>123,[1]=>name=>aasdsad,image=>bvbv,price=>45454)这就是看起来的样子,你有两次相同的记录。看看你是如何构建这个数组的。既然名称和价格都在迭代,为什么它只停留在一张图片上?是的,实际值是不同的,这只是一个例子。
<?php echo preg_replace('/\s+/', '%20',$hc['image']);?>
<?php echo rawurlencode($hc['image']);?>
<?php echo urlencode($hc['image']);?>
<?php echo preg_replace('/\s/', '%20',$hc['image']);?>