Home > Backend Development > PHP Tutorial > PHP中str_replace的指定替换次数不生效

PHP中str_replace的指定替换次数不生效

WBOY
Release: 2016-06-20 12:29:44
Original
1210 people have browsed it

<?php header("Content-Type: text/html; charset=utf-8");$str="hello world he,he,he,he,he,he";echo str_replace("he", "替换", $str,$count=1);?>
Copy after login

指定替换次数为一次,  但是结果是被全部替换,  php版本是5.4


回复讨论(解决方案)

你理解错了第四个参数,它是计算一共替换了多少次,而不是限制替换的次数

str_replace("he", "替换", $str,$count);
$count是返回被替换的次数

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