How to do this replace

Discussion in 'PHP' started by JEET, Oct 18, 2015.

  1. #1
    Hi,
    I got a string like this:

    "He winted ot go to schoool"

    which is full of typos. The correct one is:
    "He wanted to go to school."

    I have 2 corrections in my database:
    "wanted to" and "school"

    A script is trying to find the best match and replace errors with correct words.

    I cannot figure out how to split the string so I can do the check.
    If I explode it using white space, the first one "winted ot" doesn't get replaced because it gets divided into 2 parts and no match is found in the database.
    Only the second one gets detected and replaced because it's a single word.

    What to do?
    I don't know if the question is clear or not...
     
    JEET, Oct 18, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    The best bet would be to have a heuristic comparison word for word - ie, you would have to amend the database to only have single words. If not, you could pull stuff from the database that matches some of the words in the text (winted ot) would (if the script is smart enough) match "wanted" and then "to". There are many ways to make this happen, but the easier/smart way would be to keep the content in the database as simplistic as possible.
     
    PoPSiCLe, Oct 18, 2015 IP