我尝试在下划线破折号之后获取姓氏
$x = "John_Chio_Guy";
Run Code Online (Sandbox Code Playgroud)
输出应该是:Guy
这是我当前的代码:
$x = "John_Chio_Guy";
$x = preg_replace("/^[^_]*_\s*/", "", $x);
echo $x;
//output : Chio_Guy
Run Code Online (Sandbox Code Playgroud)
你可以使用爆炸功能,这太简单了
<?php
$x = "John_Chio_Guy";
//explode the string
$explode = explode('_', $x);
//get the end value
echo end($explode);
?>
Run Code Online (Sandbox Code Playgroud)