Return the portion of a string before the first occurrence of a character in php

前端 未结 5 1471
予麋鹿
予麋鹿 2020-11-28 09:41

In PHP, what is the simplest way to return the portion of a string before the first occurrence of a specific character?

For example, if I have a string...

\"

5条回答
  •  感动是毒
    2020-11-28 10:01

    How about this:

    $string = "The quick brown fox jumped over the etc etc.";
    
    $splitter = " ";
    
    $pieces = explode($splitter, $string);
    
    echo $pieces[0];
    

提交回复
热议问题