I have a lot to learn as far as regular expressions are concerned.
I have an associative array like so:
array(
"label"=>"Special",
"title"=>"Category",
"onclick"=>"dosomething()",
"options"=>array(
"one"=>"something"
)
)
I am trying to use preg_match_all on the array like so:
$match="on*";
foreach ($value as $param=>$text) {
if (preg_match_all("/".$match."/",$param,$matches)) {
$return.=" ".$param."='".$text."'";
}
}
return $return;
My problem is $return ends up looking like this:
options='Array' onclick='dosomething()'
Obviously, my regex is wrong. on* is not sufficient – It is matching ‘options‘ as well. 🙁
Can anyone tell me what would be correct regex to use?
You’re testing for “on” anywhere in the string. You’ll need to anchor the “on” to the front of the string with this:
Cheers.