I have the following string in PHP:
$cars = "Ford Chevrolet Dodge Chrysler";
I am required to output which words have various properties such as: Which word ends in 'let'? Or which word starts with 'Fo'?
I am unsure how to approach this. I am familiar enough with regex formatting, and I have gotten my preg_match to identify matches, but that's only results given in 1 or 0.
So should I split up the words using the space as a delimiter and search each one for matches individually? Or is there a simpler way of going about this?
I am aware of the preg_split function, but I don't know how to actually access the split strings.
$cars = "Ford Chevrolet Dodge Chrysler";
$param1 = '/(let)+/';
$param2 = '/(fo)+/';
echo preg_match($param1, $cars);
echo preg_match($param2, $cars);
I am aware that this doesn't work, but it prints 1s and verifys to me that matches are being found for both parameters. I just don't know how to extract the full 'Chevrolet' and full 'Ford' for parameter 1 and 2 respectively.