hey there :-)
I am facing a small problem, can you recommend me something? my problem is like this:
now when a user searches some keywords on my website i extract data of website which includes complete page details. at a time i am fetching 10 results!
so now assume

while($out=mysql_fetch_assoc($res))
{
    echo $out['full_txt']; // this echos complete page i.e. each and everything on page!
    // this $out['full_txt'] is a string!
}

Now what i want to do is Depending upon keywords searched, i want to extract lines from this full_txt . Eg. I searched "hello world"
then i want to display website description as the lines which consists of either hello or world or both . The description is required to be modified from $out['full_txt'] thing. How can I achieve it? help would be really appreciated. thank you so much!
Here the words are the keywords searched by user. Help is really very much appreciated.

Is there any way that substr or other function can help me out from this situation?

Member Avatar for diafol

SO you want to output just the sentences with the keywords? And list them underneath a page link, like a google search?

Give an example of your input, keyword, and desired output. It would be much easier for us to recommend something.

Ardav you got it exactly right.. I wanna display output like how google shows description!

@ardav and @ pritaeas I am making a search engine as project.. I have completed with almost everything else, Only part remaining is how to show Google Like Description?
If i am searchin a query on google, google gives description as lines containing those searched keywords.

Here in my search engine i got a column with name full_text which consists of everything in a webpage. I want to extract only those lines which consists any of the keywords searched and show it to user.

Thanks in advance :-)

Member Avatar for diafol

1) Decide how many displays you want per 'page' (record).
2) Search for your keywords in an SQL/DB using MATCH/FULLTEXT?
3) For each record, cut all sentences into lines (using explode on "\n" or ". " or ".\n") - this may will be different if your content is stored in html format.
5) Print the page title
4) Loop through the lines, one at a time, echoing the first say 3 line hits as text in an array, but keep looping to get the total hits number.
5) Echo a last line saying something like 'Displaying 3 out of [27] matches for this page'. Where the 27 is the total number of line hits for that record.

Is that the sort of thing?

Have a go, have a little play. Come back if stuck.

How do I extract 10-15 words separated by "Space" starting from a particular word. Example:
"Welcome to the world of java. Java is platform independent and one of the easy to learn language."
Now I want to extract the 5 words from last occurance of java. i.e.
Output should be : Java is platform independent and
How can I achieve this? I am stuck here :'(

foreach($words['hilight'] as $word) {
            $tmp=strtolower($fulltxt);
            $len=strlen($tmp);
            $found_in=strpos($tmp,$word);
            if(!($found_in==''))
            {
                if($count_of_words==1)
                $dsc=$dsc." ".substr($tmp,($found_in),160);
                else 
                $dsc=$dsc." ".substr($tmp,($found_in),60);
            }               
            }

something like above code I am using. But what happens is sometimes for example: instead showing complete word "the" it outputs "t" because of 160 is the length which i specified to be extracted.

After running above script I got output like:

java tutorials introduction introduction t tutorials trainings books social tutorials trainings books social
as you can see after introduction instead of the , it shown only 't'.
Please give some suggestions/ideas.
thanks

Member Avatar for diafol

Sorry on holiday at the mo, so can't post code v well via mobile. Will be back by sat. In meantime, anybody else?

@ardav thanks bro :-)
actually I wanna solve this problem asap :'(
project submission is coming ahead so I have to finish this thing..! I am able to finish up everything else :-)

Ok i have managed to solve this problem! Thanks!!
What I did is:

    $dsc=$dsc." ".substr($tmp,($found_in),160);
    $dsc=substr($dsc,0,strpos($dsc," "))

all solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.