eregi with regular expressions help please...!!
Posted: Fri Apr 02, 2004 7:42 am
Hi guys and girls
I have spent a few hours trying to get the result I need, but no luck, or at least for exactly what I need. I am trying to use eregi() to match a number of keywords against $words in exploded array.
Confused? Let me explain more.
The reason I need to do this is because I am using it to strip words out of text result until one or more keywords are found. I do this to show a max 50 words preview of a pages content in search results, but to start content "preview" where it finds the keyword(s).
Example...
say this is the paragraph in a page:
It could be said that, but for an obscure thirteenth century manuscript,
The Lord of the Rings might never have seen publication. Most people who
have expressed something more than a passing fancy sooner or later hear
that Tolkien actually pulled The Lord of the Rings from consideration by
its eventual published, George Allen & Unwin, and submitted the work
instead to Milton Waldman at Collins.
now say the keywords are: thirteenth and Rings
the preview would be:
thirteenth century manuscript,
The Lord of the Rings might never have seen publication. Most people who
have expressed something more than a passing fancy sooner or later hear
that Tolkien actually pulled The Lord of the Rings from consideration by
its eventual published, George Allen & Unwin, and submitted the work
instead to Milton Waldman at Collins.
OR
Rings might never have seen publication. Most people who
have expressed something more than a passing fancy sooner or later hear
that Tolkien actually pulled The Lord of the Rings from consideration by
its eventual published, George Allen & Unwin, and submitted the work
instead to Milton Waldman at Collins.
Which ever keyword it finds first is the goal.
Here is what I have now
Now, this works, but only using the first keyword
if I do this
It tends to grab the second keyword first.
So I hope your following me here...!
I need the check multiple $search_keys against the $words.
I am assuming I need to do this with regular expressions which I really dont know much about. I have been trying to learn though, its just for the begining, these expressions look like crazy people typing errors!!
If you have any ideas or preferably code samples, that would be GREAT!
Thanks in advance,
Chris
I have spent a few hours trying to get the result I need, but no luck, or at least for exactly what I need. I am trying to use eregi() to match a number of keywords against $words in exploded array.
Confused? Let me explain more.
The reason I need to do this is because I am using it to strip words out of text result until one or more keywords are found. I do this to show a max 50 words preview of a pages content in search results, but to start content "preview" where it finds the keyword(s).
Example...
say this is the paragraph in a page:
It could be said that, but for an obscure thirteenth century manuscript,
The Lord of the Rings might never have seen publication. Most people who
have expressed something more than a passing fancy sooner or later hear
that Tolkien actually pulled The Lord of the Rings from consideration by
its eventual published, George Allen & Unwin, and submitted the work
instead to Milton Waldman at Collins.
now say the keywords are: thirteenth and Rings
the preview would be:
thirteenth century manuscript,
The Lord of the Rings might never have seen publication. Most people who
have expressed something more than a passing fancy sooner or later hear
that Tolkien actually pulled The Lord of the Rings from consideration by
its eventual published, George Allen & Unwin, and submitted the work
instead to Milton Waldman at Collins.
OR
Rings might never have seen publication. Most people who
have expressed something more than a passing fancy sooner or later hear
that Tolkien actually pulled The Lord of the Rings from consideration by
its eventual published, George Allen & Unwin, and submitted the work
instead to Milton Waldman at Collins.
Which ever keyword it finds first is the goal.
Here is what I have now
Code: Select all
$words = explode(" ", $result_page_text);
for ($t = 0; $t < count($words); $t++)
{
if (!eregi("$search_keys[0]", "$words[$t]"))
{
str_replace("", $words[$t], $result_page_text);
}
else
{
$truned_text = implode(" ", array_slice($words, $t));
}
}Now, this works, but only using the first keyword
if I do this
Code: Select all
if (!eregi("($search_keys[0]|$search_keys[0])", "$words[$t]"))So I hope your following me here...!
I need the check multiple $search_keys against the $words.
I am assuming I need to do this with regular expressions which I really dont know much about. I have been trying to learn though, its just for the begining, these expressions look like crazy people typing errors!!
If you have any ideas or preferably code samples, that would be GREAT!
Thanks in advance,
Chris