e1seix Posted June 19, 2008 Share Posted June 19, 2008 Trying to find a way to use regex within an if statement. I have the following: preg_match('/Mens Fragrance > ?' (.+?)?<\/div>/', $mCat, $match); $out = $match[2]; it's a bit of a mess. Basically $mCat will always be "Mens Fragrance > SOMETHING" obv the SOMETHING being the variable. any ideas? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 if (preg_match()) { } O_O Quote Link to comment Share on other sites More sharing options...
phpSensei Posted June 19, 2008 Share Posted June 19, 2008 As DarkWater Said, use that preg_match under paranthesis and it will return 1:True or 0:False. Quote Link to comment Share on other sites More sharing options...
e1seix Posted June 19, 2008 Author Share Posted June 19, 2008 if (preg_match()) { } O_O lol. it's not so much that as the whole bit of code contained within the regex. because of the ">" within the regex i'm confused and sure i don't have the ? marks and the 's in the right place... many thanks, Quote Link to comment Share on other sites More sharing options...
e1seix Posted June 19, 2008 Author Share Posted June 19, 2008 OK, if we forget the whole if statement part, what is missing from this regex code. something needs to be encapsulated i'm sure, well i know! lol preg_match('Mens Fragrance > (.+?)', $mCat, $match); Quote Link to comment Share on other sites More sharing options...
dsaba Posted June 20, 2008 Share Posted June 20, 2008 Trying to find a way to use regex within an if statement. I have the following: preg_match('/Mens Fragrance > ?' (.+?)?<\/div>/', $mCat, $match); $out = $match[2]; it's a bit of a mess. Basically $mCat will always be "Mens Fragrance > SOMETHING" obv the SOMETHING being the variable. any ideas? $mCat = 'Mens Fragrance > bla bla bla something div <div></div>'; if (preg_match('/Mens Fragrance >(?P<something>.+?)<\/div>/', $mCat, $match)) { print_r($match); } http://nancywalshee03.freehostia.com/regextester/regex_tester.php?seeSaved=g2qsmaw5 You make us work too hard to find out what you're really asking. What comes after 'something' is pretty important to this type of pattern, from your limited explanation that should work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.