phpsubstringsubstrstrposstrlen

Is there a PHP function for printing a substring based on strpos and strlen?


I'm trying to get words before and after a string in a $body that's taken from a MySQL entry. I'm able to find the keyword in the body, get its strpos and its strlen.

From there I believe I should be able to tell it to print X characters (or ideally words) before and after that, but I can't seem to find how.

Is there a PHP function that tells it to start at $strpos and then somehow use the strlen and print before and after that?


Solution

  • substr()