Can php be replaced in a loop?

藏色散人
Release: 2023-03-13 15:58:01
Original
1580 people have browsed it

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.

Can php be replaced in a loop?

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 technicians

There 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[&#39;des&#39;],&#39;###&#39;); //4
                                $str = $o[&#39;des&#39;];  ---注意$str的位置,在for循环外面
                                for($i=1;$i<=$num;$i++){
                                    $in = "<input type=&#39;text&#39; class=&#39;space&#39; name=&#39;in$i&#39;/>";
                                    $str = preg_replace("/###/","$in",$str,1);   --注意变量名称必须与要查找到字符串变量名一致,因为是循环替换每一个,要变成不同name值。
                                }
                                echo $str;
                            ?>
Copy after login
###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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template