$str1 = "HEADINGLEY";
$str2 = "HDNGLY";
how can i seach string 1 to see if it contains all the characters from string 2 in the order they exist in string 2 and return a true or false value ?
Any help appreciated 😀
if this helps, this is the code i have todate..
echo preg_match('/.*H.*D.*N.*G.*L.*Y.*/', $str1, $matches);
returns 0
I guess I’d use
preg_matchhttp://us.php.net/manual/en/function.preg-match.php
…and turning
$str2into a regular expression usingstr_splitto get an array andimplodeto turn it back into a string with".*"as glue between characters.http://us.php.net/manual/en/function.str-split.php
http://us.php.net/manual/en/function.implode.php
Upate — I should have suggested str_split instead of explode, and here is the code that will get you a regular expression from
$str2