Re: (preg_match ?
| From: | Phillip Bow | Date: | Fri, 27 Jul 2001 00:13:18 +0000 |
| Subject: | Re: (preg_match ? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-10818@lists.php.net to get a copy of this message | ||
This works only if the list is space delimited because of the \b:
$search = "TheName";
$data = "TheName TheAddress ThePhone";
if (preg_match("/\b$search\b/i", $data))
{ echo "True<br>"; }
else { echo "False<br>"; }
However as your list is now this works:
$search = "TheName";
$data = "TheName,TheAddress,ThePhone";
if (preg_match("/$search/i", $data))
{ echo "True<br>"; }
else { echo "False<br>"; }
--
phill
<phpnet@SeaPort6.com> wrote in message
news:3B60AC492BC.DF36PHPNET@192.168.1.6...
> What's wrong with this use of preg_match?
>
> $search = "TheName"
> $data = "TheName,TheAddress,ThePhone"
>
> if (preg_match('"/\b'.$search.'\b/i"', $data))
> {
> echo "True<br>";
> }
> else
> {
> echo "False<br>";
> }
> I am trying to see if the search name matches exactly a name in the $data.
> Thanks
> Dave