Jump to content

php strings problem


razaviv

Recommended Posts

hello, im using php strings functions to creat a search, these functions are just annoying - they causing alot of problems and wont works!so first:my algorithm for the search engine is:take every data from database,take the query/the something i want relatedcompare the query to the database data:1. if the query is: "i want to buy a new car"2. and in the database there is: "new car for sell!"i want to do something like this:check if: "i" is included in the second phrase,check if: "want" is included inthe second phrase,check if: ""to" is included in the second phrase AND SO FOR AND SO ON til the sentence ends.so i tried to do this: take the word from the 0 character to the character SPACE - check if she is included by the requiered sentence,and then delete her from the first one.on every words that is include in the first and the second sentences i plus the id of the same data + 5then i print the top 25 ranked (related issues/or search engine)NOW THE PROBLEM!!!!if use string function on some variable, this var is dead - i should creat a new one to act again.and really much more problems like that.. is the php has a bug or something?EXAMPLE:

$stringx = $rowRelated['kickSideA'] . " " . $rowRelated['kickSideB'];function recorsia($string, $num){if ($num>0){$whereSpace = strpos($string, " ", 0);$word = substr($string, 0, $whereSpace);echo $string = str_replace($word, null, $string) . "2 <br>";$num--;recorsia($string, $num);}elseecho $string;}echo recorsia($stringx, '3');

this should output the string each time without the first word until num = 0 that means 3 times.it display the damn with only one cut!!!!!1what the ###### wrong with this?thanks for help

Link to comment
Share on other sites

hmm, this prhase is just an instance, i dont know what the text will be, i select it from database - so i cant know what are the keywords, so i must include every words - the definition of "word" in this case is: what comes before the SPACE character, i can make some if's so the connect words will be down.but how do i use the php strings so it will works? what i do should work perfect - but php probably has some rules in these function, i mean rules like cookie and headers - they cannot be placed after any output - if you dont know this, it wont works.. probably same here..

Link to comment
Share on other sites

One problem is that you're replacing values with null. null has a special meaning in a string, it means the end. If you want to remove something from a string then replace it with an empty string, not null.I'm wondering why you're trying to use manual searching with string functions when you have a database available to you to do the searching in though.

Link to comment
Share on other sites

My suggestion: strip out all the "noise" words and then do a "LIKE" search. So a term like "i want to buy a new car" would be boiled down to "buy new car", like what wirehopper suggested. The term "new car for sell" would become "new car sell" ("sale", actually). Short list of noise words:about,after,all,also,an,and,another,any,are,as,at,be,because,been,beforebeing,between,both,but,by,came,can,come,could,did,do,each,for,from,getgot,has,had,he,have,her,here,him,himself,his,how,if,in,into,is,it,likemake,many,me,might,more,most,much,must,my,never,now,of,on,only,or,otherour,out,over,said,same,see,should,since,some,still,such,take,than,thatthe,their,them,then,there,these,they,this,those,through,to,too,under,upvery,was,way,we,well,were,what,where,which,while,who,with,would,you,your,aMuch larger lists can be found on teh intarweb.

Link to comment
Share on other sites

hmm actually i tried use empty string and also null, they two wont work. its probably because php developers wanted us to use thier functions instead of write them byourseves, i use the explode function to get the words in the sentence very easy.and LIKE search is not good. im using it only to illustrate with live search, but the search it self will not give you results:if you search like this:a. "i want buy a red bugatti carand in database the name is wrriten like this:b. amazing BLUE bugatti carthis wont find this.LIKE method search by characters only, also if you type "Playstation 3" and there are only "Playstation 2" it wont find it.my search is built to find just anything, this is how google and youtube works also.now i solved the problem - my search is very easy algorithm, just was a problem of php functions - but as i said before, php developers wanted us to use thier functions instead write by ourselves.oh and by the way, my english is not so good, and i also dont have strength to invest to write it well..thanks anyway

Link to comment
Share on other sites

hmm actually i tried use empty string and also null, they two wont work. its probably because php developers wanted us to use thier functions instead of write them byourseves,
you don't really believe that, do you!? what would be the point of programming if not to create unique (as well as common) solutions to all kinds of problems. :)
Link to comment
Share on other sites

It sounds like you don't understand how to use LIKE. LIKE is a wildcard search. If you were going to use LIKE, you would split the words up and build the query to search for each word. e.g.:SELECT * FROM table WHERE (field LIKE '%buy%' OR field LIKE '%bugatti%' OR field LIKE '%car%')But I don't think you want to use LIKE, it sounds to me like you want to use a fulltext search instead. The syntax for a fulltext search is to use MATCH .. AGAINST instead of LIKE. LIKE is only a wildcard search.PHP works fine, and SQL works fine, it sounds like you just don't know how to use them to do what you want to do and maybe you haven't invested enough time in learning them (like English).

Link to comment
Share on other sites

you don't really believe that, do you!? what would be the point of programming if not to create unique (as well as common) solutions to all kinds of problems. :)
i mean the basic functions, not what to do with them.. :\for example: if you have an array and you want count it, you should not do a while loop for it,because you have the count() function. this is my point, i didnt realy mean they BLOCK it, but the point is that its much much muchhh smarter use thier built functions for such things, instead of spent so much time for these calculates - so i sorry if you got me incorrect, maybe didnt explain good.oh and the loop of LIKES issue:i prefered use the php by myself to learn the string functions better, instead let the sql do it for me.its just this time and not anytime.. now im really better in string functions thanks to it.i work on related issues and search engine, in the search engine i will not spent time to write it bymyself because i already know how it works,so i will let sql do it for me, same as you told.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...