|
Posted by Rik Wasmus on 01/02/08 21:28
On Wed, 02 Jan 2008 21:49:59 +0100, Poster <poster@poster.com> wrote:
> I am trying to pass an array of titles through an array of "keywords".=
=
> The $filter_test will later be replaced with real data coming from =
> another source, I am testing it this way to save time.
>
> I have this:
>
> $filter_test =3D array("Thundarr the Barbarian", "Cash and Treasure", =
=
> "Welcome Back Kotter", "Amazing Race", "The Waltons");
> $filter_title =3D array("Thundarr", "Cash", "Kotter");
>
> foreach($filter_test as $valtest) {
> foreach($filter_title as $val) {
> if (preg_match("/\b" . $val . "\b/i", $valtest)) {
> echo "MATCH " . $valtest . "\n";
> } else {
> echo "NO MATCH " . $valtest . "\n";
> }
> }
> }
>
> The problem is, this is what is returned:
>
> MATCH Thundarr the Barbarian
'Thundar' matches 'Thundar the Barbarian'
> NO MATCH Thundarr the Barbarian
'Cash' does not match 'Thundarr the Barbarian'
> NO MATCH Thundarr the Barbarian
'Kotter' does not match 'Thundarr the Barbarian'
> NO MATCH Cash and Treasure
'Thundar' does not mathc 'Cash and treasure'
etc. etc, no problem there.
> Why does it only match on the first, then no match on the other =
> identical entries ? Please go easy, this is my attempt at both arrays =
=
> and preg_match.
Keep in mind the inner most foreach will be run entirely before the seco=
nd =
entry of the outer foreach.
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|