You are here: PREG_MATCH and arrays « PHP Programming Language « IT news, forums, messages
PREG_MATCH and arrays

Posted by Poster on 01/02/08 20:49

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 = array("Thundarr the Barbarian", "Cash and Treasure", "Welcome
Back Kotter", "Amazing Race", "The Waltons");
$filter_title = 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
NO MATCH Thundarr the Barbarian
NO MATCH Thundarr the Barbarian
NO MATCH Cash and Treasure
MATCH Cash and Treasure
NO MATCH Cash and Treasure
NO MATCH Welcome Back Kotter
NO MATCH Welcome Back Kotter
MATCH Welcome Back Kotter
NO MATCH Amazing Race
NO MATCH Amazing Race
NO MATCH Amazing Race
NO MATCH The Waltons
NO MATCH The Waltons
NO MATCH The Waltons

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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация