Search code examples
phpstringsubstringwords

php find word in string by char(letter) position


Is there any way to find the word in a string by having one of the letter's position in the string. I mean if there is any easy way of doing it.

I have a string for example with 250 chars and 70 words. I would need to limit the string in my div so I need to get the whole string with complete words before char 100.


Solution

  • here is the simplest answer:

    substr($text, 0, strrpos(substr($text, 0, 100), " " ));