$text = 'we need to send products ACE66765, ACE33453, and ace72345 back to the customer.';
Set the variable $text to the string.
$regex = '/ACE\d{4}/i';
Defines the Rex-Ex(http://en.wikipedia.org/wiki/Regular_expression) searchpattern to look for words starting with ACE and having a min. of 4 numbers
$productNumbers = getPartsWithRegex($text, $regex);
Sets the variable $productNumbers as an array to the returned value of the function getPartsWithRegex.
The arguments of the function are the previous two variables defined. $text and $regex.
foreach($productNumbers as $productNumber){
echo $productNumber . '<br/>';
}
Loops through the array $productNumbers - as $productNumber. $productnumber is the value of the field. Each time printing the $productNumber followed by
- HTML newline.
function getPartsWithRegex($text, $regex) {
preg_match_all($regex, $text, $array);
return $array[0];
}
Defines the function called earlier, to call preg_match_all. Defines a table with all found matches. (Third argument $array).