Page 1 of 1
modify string for search!
Posted: Fri Mar 13, 2009 10:42 pm
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:
- strip symbols unless " , . + -
- strip + or - if they are at the end of the word like "foo+ bar+"
- strip + when it means space like "foo+bar"
- aim words between "..." as one word
in case 1 I tried to replace them with regular expression but I failed somehow
I found this forum my last chance
thanks for your attention and help
p.s. I don't want to use any classes and want it work in php4
Re: modify string for search!
Posted: Sat Mar 14, 2009 2:06 am
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.
Re: modify string for search!
Posted: Sat Mar 14, 2009 2:37 am
by ..::Behzad::..
thanks for your attention

you mean I should post it in that regex forum?
Re: modify string for search!
Posted: Sat Mar 14, 2009 3:28 am
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".
Re: modify string for search!
Posted: Sun Mar 15, 2009 3:32 am
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

Re: modify string for search!
Posted: Sun Mar 15, 2009 6:28 am
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:
- strip symbols unless " , . + -
- strip + or - if they are at the end of the word like "foo+ bar+"
- strip + when it means space like "foo+bar"
- 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?
Re: modify string for search!
Posted: Sun Mar 15, 2009 8:48 am
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

Re: modify string for search!
Posted: Sun Mar 15, 2009 8:58 am
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:
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.