I need to split string by just finding the first character. What is the quickest way to write it?
An example of string:
$string = 'Some text here| some text there--and here|another text here';
Expected result:
$new_string = 'Some text here';
This is a solution, I have. Is there a more efficient way to do it?
$explode = explode('|', $string);
$new_string = explode[0];
Use
strpos()andsubstr().Strpos()will return as soon as the first occurrence is found, whileexplode()has to walk the whole string.