Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4021228
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:19:33+00:00 2026-05-20T10:19:33+00:00

I am trying to build a search system and retrieving matching records. in this

  • 0

I am trying to build a search system and retrieving matching records. in this case.. i wanna let users use some especial chars for exactly build their requests. so i put these signs and then converting them to a correct SQL:
+ should be converted ro AND
/ should be converted ro OR
“ should be converted ro ( or )
for example when user entered: “book/pen”+paper
it should be converted to SQL WHERE clause:
( (myfield LIKE “%book%”) OR (myfield LIKE “%pen%”) ) AND ( myfield LIKE “%paper%”)
i implemented this with a switch case and arrays.. but i guess that there are another quick way to do that (such as regEx). have you any idea for solving it?

NOTE 1: I should collect all term from this expression and save them in another table. so, i need to collect them in an array.
NOTE 2: terms can be write in all world languages! from English to Arabic,Persian,.. may be Chinese!!!!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:19:34+00:00Added an answer on May 20, 2026 at 10:19 am

    Have a try with :

    $str = '"book/pen"+paper';
    // First: replace all keywords (assuming they don't contain " / + by SQL LIKE
    $str = preg_replace('#([^"/+]+)#', "(myfield LIKE '%$1%')", $str);
    // then replace / by OR
    $str = preg_replace("#/#", " OR ", $str);
    // then replace + by AND
    $str = preg_replace("#\+#", " AND ", $str);
    // and finaly replace pair of "" by ()
    $str = preg_replace('/"([^"]+)"/', "($1)", $str);
    echo $str,"\n";
    

    output:

    ((myfield LIKE '%book%') OR (myfield LIKE '%pen%')) AND (myfield LIKE '%paper%')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a Quicksilver style search system for the internal web app
I'm trying to build a search for our internal support database - each support
I am trying to build a search engine using java and the lucene API
I was trying to build a 'site search' on a simple http site. I
I'm trying to build an android app that would do a local search on
I'm trying to build a local version of the freebase search api using their
I'm trying build an App Engine connected Android application and am having some problems
I'm trying to build a filtering system for products. Products have many attributes including
I'm trying to use standard system header files in my C++ XCode project: #include
I'm currently trying to build a filter search function using JQuery and Ajax. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.