Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print part of text starting form a given keyword

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
how can i print a part of the text starting form a given keyword? (Yahoo like search)
e.g.:
i have this text:
--------------------------------------------
This PHP function lets you easily highlight e.g. search results on a specific website. Just pass the words to highlight, the path of the page (server path) and the color to highlight with. The extraordinary property about this function is that it manages not to perform replacements inside HTML tags (which could also include the word to highlight.
--------------------------------------------

and i want to print starting the keword ( results) and ending after 10 words or 100 characters :
--------------------------------------------
results on a specific website. Just pass the words to ...
--------------------------------------------

Thanks in advance
 
Here are the basic ideas:
1. Find the keyword in the string. See: strstr() in the manual.
2. Cut it to 100 chars length. See: substr()
3. Find the right most occurrence of a 'space'. See: strrchr()
4. Append the ellipsis (...) with the concatenation operator "." (dot)
5. Print the final string.


 
or stristr for case insensitive searches

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top