separate string in two by given position

前端 未结 8 1112
萌比男神i
萌比男神i 2020-12-03 17:14
$string = \'Some string\';
$pos = 5;

...??...

$begging // == \'Some s\';
$end // == \'tring\';

What is the best way to separate string in two by

8条回答
  •  甜味超标
    2020-12-03 17:51

    What is the best way to separate string in two by given position?

    If i understand you correctly, you can do:

    $str = 'hello world';
    $pos = 5;
    
    $separated_str = substr($str, $pos);
    echo $separated_str;
    

    Result:

    world
    

    This depends on the structure of your string as there are other ways also to split the string.

提交回复
热议问题