Solved

Multiple preg_match regex on title or description

Posted on 2014-12-22
3
142 Views
Last Modified: 2014-12-22
Google has several restricted items.  I need to use regex to detect these items and flag them so they are not entered in the google shopping feed.  I can do one, I just cannot get several to work together.

example:
$a = 'Do you have any guns, knives, scopes, magazines,?';

if (preg_match('/guns/','/knives/,/scopes/,/magazine/,$a))  
    echo 'true';

Open in new window

0
Comment
Question by:lawrence_dev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 250 total points
ID: 40513991
1. Use the Regex Coach to build out your regular expressions. It's a free utility and you can see your results instantly as you type. I know regexes pretty well and still use it all the time.

2. You can group matching options like this:
(?:apples|oranges|bananas)

That will match apples OR oranges OR bananas.

if (preg_match('/(?:guns|knives|scopes|magazine)/,$a))

Open in new window

0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 40514151
You'll want to include word boundaries ( \b ) in gr8gonzo's suggestion. Otherwise, things like "shoguns" and "periscopes" will be matched as well--unless that's the behavior you want.

e.g.

if (preg_match('/\b(?:guns|knives|scopes|magazine)\b/,$a))

Open in new window

0
 

Author Closing Comment

by:lawrence_dev
ID: 40514304
Thank You!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question