Get the App
SLTechnology News&Howtos  ›  Development  › 

How to replace the first one by php preg

Shulou Source: shulou.com Published: 2022-06-01 22:37:39 11月16日 Update

This article introduces you how to replace the first php preg, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Php preg to replace the first method: 1, create a PHP sample file; 2, through the "function str_replace_limit ($search, $replace, $subject, $limit=-1)" method to achieve replacement.

This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer

How does php preg replace the first one?

PHP replacement, replacing only the first match

Function str_replace_limit ($search, $replace, $subject, $limit=-1) {if (is_array ($search)) {foreach ($search as $k = > $v) {$search [$k] ='`'. Preg_quote ($search [$k],''). '`';}} else {$search =' `'. Preg_quote ($search,''). '`';} return preg_replace ($search, $replace, $subject, $limit);}

Copy the code

$search: the string or array to replace

$replace: the value to replace

$subject: text to replace

$limit: this number replaced

Php what to use php is a nested acronym, is an English hypertext preprocessing language, its syntax mixed C, Java, Perl and php self-innovative syntax, mainly used to do website development, many small websites are developed in php, because php is open source, which makes php enduring.

On how to replace the first php preg to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Content text method more website grammar help development good code interest name character string guy partner number array file article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Linux Apple MySQL Shulou Technology