How to remove anything in a string after “-”?

后端 未结 7 953
迷失自我
迷失自我 2020-12-23 15:05

This is the example of my string.

$x = \"John Chio - Guy\";
$y = \"Kelly Chua - Woman\";

I need the pattern for the reg replace.

         


        
7条回答
  •  不知归路
    2020-12-23 15:31

    You can also use.

    strstr( "John Chio - Guy", "-", true ) . '-';
    

    The third parameter true tells the function to return everything before first occurrence of the second parameter.

    Source on strstr() from php.net

提交回复
热议问题