Home >Backend Development >PHP Problem >How to remove a certain string in a string in php

How to remove a certain string in a string in php

藏色散人
藏色散人Original
2022-01-06 10:46:172969browse

php method to remove a certain string in a string: 1. Create a PHP sample file; 2. Use the str_replace function or preg_replace function to replace the specified string with nothing.

How to remove a certain string in a string in php

#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

How to remove a certain string in a string in php?

You can use the str_replace function or preg_replace function to replace the specified string with empty, that is to say, delete the specified string:

<?php
$str = &#39;a123abc112233aaccdd321123abcd&#39;;
echo str_replace("123", "", $str);
//输出:aabc112233aaccdd321abcd a123112233/aiezu.com/aaccdd321123d
 
$str = &#39;a123abc112233/aiezu.com/aaccdd321123abcd&#39;;
echo preg_replace("#abc#i", "", $str);
//输出:a123112233/aiezu.com/aaccdd321123d

Recommended learning: "PHP Video Tutorial

The above is the detailed content of How to remove a certain string in a string 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