我想提取字符串中的最后两个数字。首先,我删除任何空格或特殊字符,并用连字符替换它们,然后如果有两个连字符,则将其删除。 ext我删除任何尾随连字符。接下来,我想提取字符串中连字符后面的最后两个字符。例如,如何提取该字符串中的最后一个字符,即1
在最后一个连字符后? awesome-page-1
。我的代码是在这里提取最后一个字符
$string = 'awesome [email protected]';
$slug = preg_replace('/[^a-zA-Z0-9]/', '-', $string);//replace spaces and special characters with space
$slug = preg_replace('#-{2,}#', '-', $slug);//two hyphens following each other
$slug = trim($slug, '-');//remove trailing hyphens
感谢的人。有用。 – sammyukavi 2013-02-19 13:49:43