Home >Backend Development >PHP Tutorial >截取字符请教

截取字符请教

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:20:411023browse

有这么一些字符
11n234
45ewd123
44se1321
er12312
1142342ew353
3ewf2324

我想匹配出最后一个字母前面的字符包括最后一个字母。
如45ewd123 匹配出45ewd

求指点


回复讨论(解决方案)

echo preg_replace('/[^a-z]+$/i','','123456ew789');

$s = '3ewf232t4a';
echo strrev(preg_replace('/\d+/', '', strrev($s), 1));

哦,上面那个有点问题。更正一下:

echo strrev(preg_replace('/^\d+/', '', strrev($s), 1));

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