Jump to content

Quick Regex Help


e1seix

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/111006-quick-regex-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/111006-quick-regex-help/#findComment-569832
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.