Welcome to WebmasterWorld Guest from 54.227.52.24

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

preg match more than 1 subject

     

tr8er8

7:42 pm on Dec 17, 2008 (gmt 0)

5+ Year Member



is it possible to have more than one subject like:

if(preg_match($pattern, $subject ¦¦ $subject2 ¦¦ $subject3)) {
//result
}

eelixduppy

8:11 pm on Dec 17, 2008 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



No it is not. You'd have to have multiple preg-matches:

if(preg_match(..) ¦¦ preg_match(..) ¦¦ preg_match(..))

coopster

12:47 pm on Dec 18, 2008 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



If it is the same regular expression, loop over your subjects ...
$subjects = array( 
'My favorite pet is a cat.',
'My favorite pet is a snake.',
'My favorite pet is a bird.'
);
$pattern = '/\s([a-z]+)\.$/';
print '<pre>';
foreach ($subjects as $subject) {
if (preg_match($pattern, $subject, $matches)) {
print "Do you have a {$matches[1]}?\n";
}
}
print '</pre>';
 

Featured Threads

Hot Threads This Week

Hot Threads This Month