How this substring example works
substr() takes a start offset and an optional length; negative offsets count from the end. strstr($s, $needle, true) returns everything before the first occurrence of the needle.
Extract part of a string with substr(). Edit the code below and press Run to execute it with real PHP in your browser.
Full: Hello, World! First 5: Hello Last 6: World! Middle: World Before comma: Hello
substr() takes a start offset and an optional length; negative offsets count from the end. strstr($s, $needle, true) returns everything before the first occurrence of the needle.