Php trim string at a particular character

前端 未结 7 1353
花落未央
花落未央 2021-01-11 18:32

Is there a php string function to trim a string after a particular character. I had a look on the php.net site and did a google search but couldn\'t find anything. The only

7条回答
  •  星月不相逢
    2021-01-11 19:20

    function imaginary_function($string, $char) {
      $index = strpos($char, $needle);
      if ($index === false) { return $string };
    
      return substr($string, 0, $index);
    }
    

    An excellent, official list of string manipulation functions is available here.

提交回复
热议问题