2016-08-15 6 views
-1

私はテーブル内にブートストラップモーダルを使用しています。そのモーダルでは画像を表示したいのですが、そのソースは反復して取得する配列にあります。しかし、絵はこれが私のコードPHPでループ内のimgタグにソースを提供するには

<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">&times;</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> 

です...

は表示されません私は、任意の参照が不足しているだろうか?そして、なぜイメージが反復されていませんが、名前と価格が反響する

array (size=2) 
    0 => 
array (size=4) 
    'name' => string ' Nvidia Geforce STRIX-GTX970-DC2OC-4GD5 GTX 970' (length=47) 
    'price' => string ' 
            Rs. 43,800                Ex Tax: Rs. 43,800 
           ' (length=64) 
    'link' => string 'http://www.hayatcomputers.com/index.php?route=product/product&product_id=1551&search=GTX+970' (length=92) 
    'image' => string 'http://www.hayatcomputers.com/image/cache/data/Nvidia Geforce/11-200x236.jpg' (length=76) 
    1 => 
array (size=4) 
    'name' => string 'NVIDIA GeForce GTX 970' (length=22) 
    'price' => string ' 
            Rs. 43,000               Ex Tax: Rs. 43,000 
           ' (length=64) 
    'link' => string 'http://www.hayatcomputers.com/index.php?route=product/product&product_id=794&search=GTX+970' (length=91) 
    'image' => string 'http://www.hayatcomputers.com/image/cache/data/Graphics Cards/NVIDIA GeForce GTX 970 Rev 1.1-200x236.jpg' (length=105) 
+1

は?=にpreg_replace( '/ \ S + < '<?phpのエコーにpreg_replace( '/ \ S + /'、 '%20'、$のHC [ '画像'])>'結果をエコー 'OR/'、'%20 '、$ hc [' image '])?>' –

+0

OMG !!!ああ、神様!!! OMGGGG !!!!!!!!!!!!!!!!!そのすべてのスキルは粉砕された!これはあなたが8時間まっすぐにコードするときに起こります! –

+0

今日は十分なプログラミング!すべてありがとうございました –

答えて

0

preg_replaceニーズです。だから、

<?php echo preg_replace('/\s+/', '%20',$hc['image']);?> 

さらに\s+は直前の文字の1以上であるので、この正規表現は、単一のURLエンコードされたスペースで複数の空白を交換され、空白ですか。おそらく期待通りには動作しません。私はちょうどrawurlencodeまたはurlencodeの内蔵を使用しています。

<?php echo rawurlencode($hc['image']);?> 

または

<?php echo urlencode($hc['image']);?> 

urlencoderawurlencode%20を使用しますが、スペースの+を使用しています。

各スペースを1つのURLエンコードスペースでスワップします。

<?php echo preg_replace('/\s/', '%20',$hc['image']);?> 
+0

画像ソースが反復していないのはなぜか分かりますか?私はすべての行が別のイメージを持っている必要がありますことを意味ですか? –

+0

Dunno、 '$ hayatcomputers'はどうなっていますか? – chris85

+0

Array([0] => name => abc、image => adad、price => 123、[1] => name => aasdsad、image => bvbv、price => 45454) これは見た目ですlike –

関連する問題