Get all of words from sentence

hi
i wana get all of words from this sentence


After having owned the BMW X3, the MDX is a pleasure to drive. Reliability is great for 25,000 miles. Only things wrong are Bluetooth; rings and cannot hear whose on the other end and many viable addresses do not show up on Navigation system. Dealer service excellent. A few miss-steps in design; no lights for A/C controls at night; rear view pic doesn't come on in reverse for 10 seconds, some wind noise, transmission can be rough and erratic. No ipod plug which I didn't realize until after I purchased. Front end design could be improved, very masculine. Sounds like a lot but I do really like this car. Also test drove BMW X5 and Lexus 400.



is there any library or prepared class to get all of words from this sentence cleaney?
i know some function is exist like preg_match…

What do you mean by “get” and what are you trying to do? Are you trying to search for duplicate content…?

Please clarify your question.

1 Like

look at this sentence"now in 2016. i am mikel and i from USA" when i get words i should get (“now”,“in”,“2016”,“i”,“am”,“mikel”,“and”,“from”,“USA”);

like this example

You won’t need a library or class. PHP has string and array functions that can do it.

Try exploding on the space
http://php.net/manual/en/function.explode.php

$test_str ="now in 2016. i am mikel and i from USA"; 
$words = explode(' ', $test_str);
print_r($words);
1 Like

Thanks

but i need clean word without any “.” or “/” or…

look at this function ;

$texts = preg_split(“/((\r(?!\n))|((?<!\r)\n)|(\r\n))/”, $text);

but i dont know how to say function delete “(” or “)” or “.” from sentence,i hope you understand me

“design;” and “drive.” do not look like proper words.

1 Like

The solution would be not to match them in the first place. :-) Try this:

preg_match_all('/\w+/', $str, $matches);    // match words
$matchesUnique = array_unique($matches[0]); // get new array w/o duplicates
print_r($matchesUnique);
2 Likes

I don’t get regular expressions. To me it would be simpler to use explode() as @Mittineague said, then write a short function to strip out anything that isn’t a letter and pass each one through that.

1 Like

… like preg_replace('/[^A-Za-z]/', '', $str)?

[runs for cover]

3 Likes

This question always boils down to a question “what the word is?”. And the answer is no that simple as it seems at first.

1 Like

Well, OK, I guess I can see that one.

1 Like

we delete stop words,after getting words of sentence,

Oh, do you mean ranking for keywords then? Ok, well if you are trying to rank for all of those keywords, it actually makes no sense. You would need to find which keywords are most useful to rank for. Generic words like “now” are worthless to optimize on and try to rank for.

If, on the other hand, you aren’t talking about keywords and optimizing a site, but instead you are trying to find that sentence in a source, that is a different conversation all together.

1 Like

Actually, if you have followed labour’s other topics, it is not about keywords or optimization.

The goal is to identify words in long text strings and highlight them according to an arbitrary color scheme based on an arbitrary “dictionary” of sorts.

.

1 Like

I can’t for the life of me see why anyone would assume this was to do with keywords or optimisation, but then it takes all sorts!

2 Likes

exactly

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.