Here is a sample PHP array that explains my question well
$array = array('1' => 'Cookie Monster (<i>eats cookies</i>)',
'2' => 'Tiger (eats meat)',
'3' => 'Muzzy (eats <u>clocks</u>)',
'4' => 'Cow (eats grass)');
All I need is to return only values that don't contain any tag enclosed with parentheses from this array:
- Tiger (eats meat)
- Cow (eats grass)
For this I'm going to use the following code:
$array_no_tags = preg_grep("/[A-Za-z]\s\(^((?!<(.*?)(\h*).*?>(.*?)<\/\1>).)*$\)/", $array);
foreach ($array_no_tags as $a_n_t) {echo "- ".$a_n_t."<br />";}
Assuming that [A-Za-z]
may be whoever, \s
is a space, \(
is the opening parenthesis, ^((?!
is start of the tag denial statement, <(.*?)(\h*).*?>(.*?)<\/\1>
is the tag itself, ).)*$
is end of the tag denial statement and \)
is the closing parenthesis.
Nothing works.
print_r($array_no_tags);
returns empty array.