preg_match() help!!! - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: preg_match() help!!! (/showthread.php?tid=85559)
preg_match() help!!! by Nathan on 08-23-2008 at 03:45 PM
Hello there,
I can't figure out for the life of me, to get preg_match() to work with arrays for example (this is not my real code, just something im exampling with off the top of my head)
code:
$comment = $_POST['comment'];
$check_for = array('/test/', '/hello/');
if(preg_match($check_for, $comment)) {
echo "hello";
} else {
echo "nope";
}
RE: preg_match() help!!! by segosa on 08-23-2008 at 03:55 PM
code: $comment = $_POST['comment'];
$check_for = array('/test/', '/hello/');
foreach ($check_for as $dt_sucks)
{
if(preg_match($dt_sucks, $comment))
echo "hello";
else
echo "nope";
}
RE: preg_match() help!!! by Nathan on 08-23-2008 at 03:59 PM
Why, thank you segosa!
RE: preg_match() help!!! by -dt- on 08-24-2008 at 12:30 AM
quote: Originally posted by segosa
$dt_sucks
pft, if he had bothered to look at the php.net page
http://php.net/preg_match he might have noticed that the signature says
quote: int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags [, int $offset ]]] )
RE: preg_match() help!!! by Nathan on 08-24-2008 at 12:39 AM
I checked the php site -dt- and I did indeed read that.
RE: preg_match() help!!! by roflmao456 on 08-24-2008 at 01:12 AM
quote: Originally posted by Nathan
I checked the php site -dt- and I did indeed read that.
array != string so a foreach or for is needed
RE: preg_match() help!!! by andrewdodd13 on 08-24-2008 at 09:08 AM
http://uk.php.net/preg_match :
Do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster.
RE: RE: preg_match() help!!! by segosa on 08-24-2008 at 03:28 PM
quote: Originally posted by -dt-
quote: Originally posted by segosa
$dt_sucks
pft, if he had bothered to look at the php.net page
http://php.net/preg_match he might have noticed that the signature says
quote: int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags [, int $offset ]]] )
but you still suck
|