What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » preg_match() help!!!

preg_match() help!!!
Author: Message:
Nathan
Veteran Member
*****

Avatar
Yeah, "large dimensions" ;)

Posts: 2984
Reputation: 76
– / Male / Flag
Joined: Apr 2005
O.P. preg_match() help!!!
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";
}


This post was edited on 08-23-2008 at 03:46 PM by Nathan.
Touch Innovation - touch friendly programs/applications for the windows mobile!


08-23-2008 03:45 PM
Profile E-Mail PM Web Find Quote Report
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: preg_match() help!!!
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";
}

The previous sentence is false. The following sentence is true.
08-23-2008 03:55 PM
Profile PM Find Quote Report
Nathan
Veteran Member
*****

Avatar
Yeah, "large dimensions" ;)

Posts: 2984
Reputation: 76
– / Male / Flag
Joined: Apr 2005
O.P. RE: preg_match() help!!!
Why, thank you segosa!
Touch Innovation - touch friendly programs/applications for the windows mobile!


08-23-2008 03:59 PM
Profile E-Mail PM Web Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
35 / Male / Flag
Joined: Mar 2004
RE: preg_match() help!!!
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  ]]] )

[Image: dt2.0v2.png]      Happy Birthday, WDZ
08-24-2008 12:30 AM
Profile PM Web Find Quote Report
Nathan
Veteran Member
*****

Avatar
Yeah, "large dimensions" ;)

Posts: 2984
Reputation: 76
– / Male / Flag
Joined: Apr 2005
O.P. RE: preg_match() help!!!
I checked the php site -dt- and I did indeed read that.
Touch Innovation - touch friendly programs/applications for the windows mobile!


08-24-2008 12:39 AM
Profile E-Mail PM Web Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: preg_match() help!!!
quote:
Originally posted by Nathan
I checked the php site -dt- and I did indeed read that.
array != string :P so a foreach or for is needed
[quote]
Ultimatess6
: What a noob mod
08-24-2008 01:12 AM
Profile PM Web Find Quote Report
andrewdodd13
Senior Member
****

Avatar
Oh so retro

Posts: 870
Reputation: 16
34 / Male / Flag
Joined: Jan 2005
RE: preg_match() help!!!
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.

:)

This post was edited on 08-24-2008 at 09:09 AM by andrewdodd13.
[Image: AndrewsStyle.png]
08-24-2008 09:08 AM
Profile E-Mail PM Web Find Quote Report
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: RE: preg_match() help!!!
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 :(
The previous sentence is false. The following sentence is true.
08-24-2008 03:28 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On