Home > Article > Backend Development > Can php be replaced in a loop?
php can be replaced in a loop. The method is: 1. Create a PHP sample file; 2. Loop through "for($i=1;$i<=$num;$i){...}" The statement can be replaced.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
Can php be replaced in a loop?
php can be replaced in a loop.
#php loop replaces the simple implementation method in turn:
$o['des'] = existing employees
, including front-line senior techniciansThere are
people for intermediate skilled workers,junior technicians, and
people for other personnel.The purpose is to replace all into input boxes
<?php $num = substr_count($o['des'],'###'); //4 $str = $o['des']; ---注意$str的位置,在for循环外面 for($i=1;$i<=$num;$i++){ $in = "<input type='text' class='space' name='in$i'/>"; $str = preg_replace("/###/","$in",$str,1); --注意变量名称必须与要查找到字符串变量名一致,因为是循环替换每一个,要变成不同name值。 } echo $str; ?>###The last parameter (N) of preg_replace is to replace several, here I think it needs to be replaced with different names in sequence value, so it is appropriate to replace them one at a time. ###### Recommended learning: "###PHP Video Tutorial###"###
The above is the detailed content of Can php be replaced in a loop?. For more information, please follow other related articles on the PHP Chinese website!