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

后端 未结 7 952
迷失自我
迷失自我 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:27

    Use the strstr function.

    Example:

    $my_string = "This is my best string - You like it?";
    $my_new_string = strstr($my_string, '-', true);
    
    echo($my_new_string);
    

提交回复
热议问题