![]() |
Getting certain keywords from a string ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Getting certain keywords from a string ? (/showthread.php?tid=19067) |
Getting certain keywords from a string ? - El Forum - 05-26-2009 [eluser]aquary[/eluser] I'm implementing my webboard using CI and thinking about using some important words from the thread title as a page keyword. I thought about putting those "important words" I want to look for into an array, then foreach and check if any of them exists in the given string. Code: $str="Some thread titile with important words"; The function would return "important, words", and I'll put it in the META tag. The concept should work, but there are too many words I want to put in the array (more that 50, I guess). The script would take some times to return the keywords. What do you think about this? Are there any other functions that can do this? Thanks ![]() Getting certain keywords from a string ? - El Forum - 05-26-2009 [eluser]CrazyMerlin[/eluser] Keep your keywords in a plain text file with 1 word on each line and load the file. Once loaded create an array from the file by loading each line into an array element. You may think this would take some time but honestly file access with PHP is super fast, and a 50 line file is nothing...I load SQL files with 200,000 + lines of SQL. Getting certain keywords from a string ? - El Forum - 05-27-2009 [eluser]Dam1an[/eluser] If you insist on doing it the array way, you could - Explode the string on a space - use array_intersect on that and the key workds array - implode the resulting array with commas ![]() Getting certain keywords from a string ? - El Forum - 05-27-2009 [eluser]aquary[/eluser] array_intersect << Oh, I haven't thought about that one. I kept thinking only about str_xxx function. That is worth trying. thanks ![]() Getting certain keywords from a string ? - El Forum - 05-27-2009 [eluser]Dam1an[/eluser] Array_intersect (and its variants) are hidden gems ![]() I used to always do stuff like that manually using a for loop until I doscovered it (via these forums of course ![]() |