This question already has an answer here:
I have two Strings. Both seems similar but one of them is the main String and the other is the Finde String.
For Example:
$MainString = 'Yellow Green Orange Blue Yellow Black White Purple';
$FinderString = 'Yellow Blue White';
My Question now is how to split those Strings in to an Array to check each one with the other one of the other string?
Here is my Tryed code:
<?php
$MainString = 'Yellow Green Orange Blue Yellow Black White Purple';
$FinderString = 'Yellow Blue White';
$resault = substr_count($MainString, $FinderString);
echo("number of matched colores: ".$resault);
?>
Resault of my Code:
number of matched colores: 0
My expection of this Code:
number of matched colores: 4
Can some one pleas help me to fix this?
--- FINAL CODE AFTER HELP: ---
Now I wrote this code it's not the best I guess but he works.
<?php
$MainString = 'Yellow Green Orange Blue Yellow Black White Purple';//declare the main String
$FinderString = 'Yellow Blue White'; //declare the finder String
$MainlyString = explode(" ",$MainString); //splitting the massive string into an Array.
$FindlyString = explode(" ",$FinderString); //splitting the massive string into an Array.
$resault = 0; //declare the counters
foreach($MainlyString as $main) { //running through the Array and give the result an Alias.
foreach($FindlyString as $find) { //runing through the Array and gave the resault an Alias.
if (substr_count($main, $find) == 1) { //Checking if a month is matching a mother.
$resault = $resault + 1; //increase the counter by one
}
}
}
echo("number of matched month: ".$resault."<br>"); //output of the counter
?>
Thanks for the help guys. :)
</div>