I want to add a substring (text) at beginning of string only if this string doesn't have already this text at beginning.
Example:
// let's say I want to add "Has" at beginning (if doesn't exist)
$string_1 = "AnaHasSomeApples"; // we need to add
$string_2 = "HsSomeApples"; // we need to add
$string_3 = "HasApplesAlready"; // already exists at the beginning
I tried this:
$string = (strpos($string, 'Has') === false ? 'Has' : '') . $string;
I know is not hard to do that.
I am more interested in finding the fastest (according to time, not lines of code) possible way.