Home  >  Article  >  Backend Development  >  How to replace specific string with null value in PHP

How to replace specific string with null value in PHP

coldplay.xixi
coldplay.xixiOriginal
2020-09-29 10:06:433597browse

PHP method to replace a specific string with a null value: 1. Use substring replacement [$id = str_replace(".html", "", $id)]; 2. Regular expression Substring replacement [$id = preg_replace("/\.html/", "", $id)].

How to replace specific string with null value in PHP

PHP method to replace a specific string with a null value:

Substring replacement:

$id = str_replace(".html", "", $id);

Or regular expression substring replacement:

$id = preg_replace("/\.html/", "", $id);

In fact, if you are sure that the string format you want to process is "string-number.html", where string consists of non-"-" and " .", then the following statement will be OK:

$array = preg_split('/[-\.]/', $querystring, -1, PREG_SPLIT_NO_EMPTY);

$array[1] is the data you want.

If you want to know more about programming learning, please pay attention to the php training column!

The above is the detailed content of How to replace specific string with null value in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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