modify string for search!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
..::Behzad::..
Forum Newbie
Posts: 7
Joined: Mon Mar 09, 2009 4:40 am
Location: Tehran, Iran
Contact:

modify string for search!

Post by ..::Behzad::.. »

hey everyone,

I'm newbie in php or maybe I should say I am a amateur!

I'm going to code a simple search engine. I don't have any problem with MySQL queries and I exactly know what should I do.
My problem is how could modify sting that should be searched. I want to modify it with properties below but I don't know how:
  1. strip symbols unless " , . + -
  2. strip + or - if they are at the end of the word like "foo+ bar+"
  3. strip + when it means space like "foo+bar"
  4. aim words between "..." as one word
in case 1 I tried to replace them with regular expression but I failed somehow :oops:
I found this forum my last chance :D

thanks for your attention and help :wink:

p.s. I don't want to use any classes and want it work in php4
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: modify string for search!

Post by php_east »

there is an sql statement LIKE, which is very useful for searches.

oops sorry, missed the "sql no problem" part. regex is the way i guess, can't think of how else.
there is a special regex area in this forum i believe.
User avatar
..::Behzad::..
Forum Newbie
Posts: 7
Joined: Mon Mar 09, 2009 4:40 am
Location: Tehran, Iran
Contact:

Re: modify string for search!

Post by ..::Behzad::.. »

thanks for your attention :wink:
you mean I should post it in that regex forum?
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: modify string for search!

Post by php_east »

yes, i believe so, that would be where exprerienced regex people are.
or maybe you could post what u have tried ( and not too successful ) here.

my guess is that you probably need several passes of a couple of regex, instead of just one regex to "do it all".
User avatar
..::Behzad::..
Forum Newbie
Posts: 7
Joined: Mon Mar 09, 2009 4:40 am
Location: Tehran, Iran
Contact:

Re: modify string for search!

Post by ..::Behzad::.. »

I used this pattern for finding symbols I want
([^a-zA-Z0-9\s\+\-",.])

Code: Select all

preg_match_all('([^a-zA-Z0-9\s\+\-",.])', $str, $match, PREG_OFFSET_CAPTURE)
It works but I don't know what should I do for the other :(
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: modify string for search!

Post by prometheuzz »

..::Behzad::.. wrote:hey everyone,

I'm newbie in php or maybe I should say I am a amateur!

I'm going to code a simple search engine. I don't have any problem with MySQL queries and I exactly know what should I do.
My problem is how could modify sting that should be searched. I want to modify it with properties below but I don't know how:
  1. strip symbols unless " , . + -
  2. strip + or - if they are at the end of the word like "foo+ bar+"
  3. strip + when it means space like "foo+bar"
  4. aim words between "..." as one word
...
Can you give a couple (more than one!) of example query strings and clearly indicate which "tokens" you wish to extract and which ti ignore?
User avatar
..::Behzad::..
Forum Newbie
Posts: 7
Joined: Mon Mar 09, 2009 4:40 am
Location: Tehran, Iran
Contact:

Re: modify string for search!

Post by ..::Behzad::.. »

prometheuzz wrote: Can you give a couple (more than one!) of example query strings and clearly indicate which "tokens" you wish to extract and which ti ignore?
I need to strip some characters from my string, ignoring symbols like `~!@#$ and... unless + - " . ,.
for example:
  • "foo@bar.com" should be change to "foo bar.com" and counted as 2 words
  • or "foo+bar+tar" should change to "foo bar tar" and counted as 3 words
  • strip extra + or - at the end of words; "foo+ bar" should change to "foo bar"
  • ""foo bar" tar" should counted as 2 words, "foo bar" and "tar"
Hope you get what I mean. and sorry for my bad English :oops:
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: modify string for search!

Post by prometheuzz »

..::Behzad::.. wrote:
prometheuzz wrote: Can you give a couple (more than one!) of example query strings and clearly indicate which "tokens" you wish to extract and which ti ignore?
I need to strip some characters from my string, ignoring symbols like `~!@#$ and... unless + - " . ,.
...
Sorry, I still don't understand. You say you want to keep thecharacters:

Code: Select all

+ - " . ,
Yet you keep the DOT in "bar.com" and you remove the PLUS from "foo+ bar".

Also, you're talking about the characters ~!@#$ yet none of your examples show them. Keep in mind that you are explaining your problem to people who are not familiar with your assignment. Explain it in such a way, otherwise I (and I suspect no one) can help you. In short: help us help you.
Post Reply