例如,我有以下字符串:
"20 Secured file A"
"20 Secured 20 files: A, B, ...."
"22 Deleted file A"
"22 Deleted 22 files: A, B, ...."
"24 Moved file A"
"24 Moved 24 files: A, B, ...."
"28 Corrupt file A"
"28 Corrupt 28 files: A, B, ...."
"All correct 20 files: A, B, ...."
"All correct 22 files: A, B, ...."
"All correct 24 files: A, B, ...."
"All correct 28 files: A, B, ...."
我可以用PHP中的哪个函数来搜索精确的"20"并将其剪切?我测试的所有函数都只让我搜索"20"而不是"20",所以第二种情况下剪切2x "20"而不是第一个"20"。
我只需要一个代码,可以削减前三个字母,但只有当他们开始与"20","22","24"或"28"
非常感谢你们:)
str_replace('24 ', '', $text);
1条答案
按热度按时间7cwmlq891#
您可以使用preg_replace函数来实现以下目的: