替换循环中的文本



我不能在循环中实现文本的自动替换。文本要么不被替换,要么被随机替换,而不是在整个循环中替换。请帮助。

<?php  
$connect = mysqli_connect("localhost", "111", "password", "222");  
$query1 ="SELECT * FROM beta ORDER BY ID DESC"; 
$result1 = mysqli_query($connect, $query1);
?> 
<script type="text/javascript">
$(document).ready(function() {
$("cost").html($("cost").html().replace('One', 'Two'));
});  
</script>
<cost>
<div class="table-responsive">
<table id="employee_data" class="row-border order-column cell-border hover">
<thead>
<tr>
<th>Name</th>  
<th width="10%">1</th>
<th width="10%">2</th>
<th width="10%">3</th>
<th width="10%">4</th>
<th width="10%">5</th>
<th width="10%">6</th>
</tr>
</thead>
<?php
while($row1 = mysqli_fetch_array($result1))
{
echo '
<tr>
<td><font face="Verdana">'.$row1["name"].'</font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["len"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["len"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["myt"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["myt"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["tr"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["tr"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["kr"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["kr"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["var"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["var"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.$row1["kor"].'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["kor"].'" /></font></td>
</tr>
';  
}
?>
</table>
</div>
</cost>

单词"One"& lt; cost> & lt;/cost>必须用"Two"代替。

别对我太苛刻,我是新手。

大感谢!

可以在php端使用str_replace函数

https://www.php.net/manual/en/function.str-replace.php

<?php
while($row1 = mysqli_fetch_array($result1))
{
echo '
<tr>
<td><font face="Verdana">'.$row1["name"].'</font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["len"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["len"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["myt"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["myt"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["tr"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["tr"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["kr"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["kr"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["var"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["var"].'" /></font></td>
<td><font color=#1341EB face="Verdana"><b>'.str_replace("One","Two",$row1["kor"]).'</b><input type="checkbox" class="checkbox-offers" name="checkbox" value="'.$row1["kor"].'" /></font></td>
</tr>
';  
}
?>

相关内容

  • 没有找到相关文章

最新更新