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)].
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!