如何在PHP中的以下场景中连接变量和字符串? [英] How to concatenate variable and string in following scenario in PHP?
本文介绍了如何在PHP中的以下场景中连接变量和字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是PHP代码:
I've following PHP code:
<?php
$rebate_no = 2;
echo "<table id='blacklistgrid_$rebate_no' class='table table-bordered table-hover table-striped blacklistgrid'>
<tr id='reb$rebate_no_1'>
<td>
<div class='btn-group'>
<select name='product_id_$rebate_no[1]' id='product_id_$rebate_no_1' class='form-control prod_list'>
<option value='1'>Alabama</option>
<option value='2'>Alaska</option>
<option value='3'>Arizona</option>
<option value='4'>Arkansas</option>
<option value='5'>California</option>
</select>
</div>
</td>
</tr>
</table>";
?>
在上面的代码中,我在变量和字符串连接方面遇到问题:
In above code I'm having issues in concatenation of variable and string at following lines:
<tr id='reb$rebate_no_1'>
<select name='product_id_$rebate_no[1]' id='product_id_$rebate_no_1' class='form-control prod_list'>
我试过下面的技巧,但它对我没用。
I tried following trick but it didn't work for me.
<tr id='reb'.$rebate_no.'_1'>
<select name='product_id_$rebate_no[1]' id='product_id_'.$rebate_no.'_1' class='form-control prod_list'>
如果我检入HTML源代码,我会收到以下HTML代码:
If I check in HTML source I'm getting following HTML:
<tr id="reb" .2.'_1'="">
<select id="product_id_" class="form-control prod_list" .2.'_1'="" name="product_id_">
其实我想要HTML格式如下:
Actually I want the HTML in following desired format:
<tr id='reb2_1'>
<select name='product_id_2[1]' id='product_id_2_1' class='form-control prod_list'>
如何做到这一点?
推荐答案
字符串连接
String concatenation
<?php
$rebate_no = 2;
echo "<table id='blacklistgrid_".$rebate_no."' class='table table-bordered table-hover table-striped blacklistgrid'>
<tr id='reb".$rebate_no_1."'>
<td>
<div class='btn-group'>
<select name='product_id_".$rebate_no[1]." id='product_id_".$rebate_no_1."' class='form-control prod_list'>
<option value='1'>Alabama</option>
<option value='2'>Alaska</option>
<option value='3'>Arizona</option>
<option value='4'>Arkansas</option>
<option value='5'>California</option>
</select>
</div>
</td>
</tr>
</table>";
?>
OR
如果您想使用Zend规范
OR If you want to use the Zend specification
<?php
$rebate_no = 2;
echo "<table id='blacklistgrid_{$rebate_no}' class='table table-bordered table-hover table-striped blacklistgrid'>
<tr id='reb{$rebate_no_1}'>
<td>
<div class='btn-group'>
<select name='product_id_{$rebate_no[1]} id='product_id_{$rebate_no_1}' class='form-control prod_list'>
<option value='1'>Alabama</option>
<option value='2'>Alaska</option>
<option value='3'>Arizona</option>
<option value='4'>Arkansas</option>
<option value='5'>California</option>
</select>
</div>
</td>
</tr>
</table>";
?>
这篇关于如何在PHP中的以下场景中连接变量和字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文