我有这个字符串。我想删除" 0002。"但它也删除了22.如何删除前导数字和点(。)然后停止删除任何数字?
$title = "0002.22 Greatest Voices In The Business (Current Female Singers Only)";
$words = preg_replace('/[0-9]+./', '', $title );
输出:
Greatest Voices In The Business (Current Female Singers Only)
预期产出:
22 Greatest Voices In The Business (Current Female Singers Only)
答案 0 :(得分:1)
那么,你需要删除从字符串开头到点的所有数字吗?
使用^
表示"字符串开头"
$title = "0002.22 Greatest Voices In The Business (Current Female Singers Only)";
$words = preg_replace('/^[0-9]+\./', '', $title );
如果你需要删除任何数字后跟点,你的代码是正确的,除了点是特殊字符,需要转义。
$title = "0002.22 Greatest Voices In The Business (Current Female Singers Only)";
$words = preg_replace('/[0-9]+\./', '', $title );