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

  • SEARCH
  • Home
  • 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 8185811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:58:40+00:00 2026-06-07T01:58:40+00:00

I want to make a product search engine where the user types in a

  • 0

I want to make a product search engine where the user types in a product code and it will bring back the result, this is easy.

But, I want to be able to compensate for numbers that look like letters and vice versa.

E.g a user types 6O12l, but the product code is actually 60121.

What do I need to put in the SQL query to bring back all products with 6O12l and/or 60121?


So far I have this which isn’t working, it keeps bringing back the same result everytime no matter what I type in:

$searchString = $_POST['query'] ;
$searchString = preg_replace('#\W#', '', $searchString);

$firstLetter = substr($searchString, 0, 1) ;

include("db.php") ;

$result = $dbh->prepare("SELECT productCode
                     FROM products
                     WHERE productCodeREGEXP '6[O0]12[1l]'
                     AND productCode LIKE '$firstLetter%'") ;
$result->execute() ;

while($row = $result->fetch(PDO::FETCH_ASSOC)) {
echo $row['productCode'].'<br />' ;
}

I have managed to get it working, but I have encountered a new problem.

I’m using str_replace to substitute the letters for numbers and viceversa in the users query string, but it will only work for one or the other, not both:

$qString = str_replace(array('o', 'l', '0', '1'), array('[O0]', '[1l]', '[O0]', '[1l]'), $searchString) ;

Which gives me a mangled output of e.g. A[[1l]l]BC
Instead of A[1l]BC

  • 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-06-07T01:58:43+00:00Added an answer on June 7, 2026 at 1:58 am

    Do you have product codes with letters? You can translate the query string to all numbers before you run the query. That’s the easiest thing to do, and will be much faster than testing for both.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make some product to offer key-value data system. but local memory
I want make interactive application where user launches it and can do various task
I'm trying to make mini search engine for a site containing products. I've already
I'm sure this has been asked but I can't quite find the right search
I'm trying to make a feature in a product which gives the user the
I just want to make some HTML page with this layout . How could
I want to make a java class that would print out: The product of
I hope this isn't a duplicate of a question itself, but the search terms
i want to make sure all product names are unique so i tried to
I want to make some performance measures (mainly runtime) for my Java code, a

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.