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

How to replace specific string with null value in PHP

coldplay.xixi
Release: 2023-03-06 09:18:01
Original
3702 people have browsed it

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);
Copy after login

Or regular expression substring replacement:

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

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);
Copy after login

$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!

Related labels:
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