![]() The default behaviour of this function is to return the substring of a string after the first match of a character. $string = 'This is a sentence of text.' $output = strtok ( $string, ' ' ) print ( $output ) ThisĪnother clean way of achieving the same result is to use the PHP strstr() function. Pass the string to check as the first argument and the character to look for as the second. The easiest way to get a substring before the first occurrence of a character such as a whitespace is to use the PHP strtok() function. We will explore some of the best methods in this tutorial so you can determine which one best fits your specific scenario. Use the PHP mb_substr() function to extract a substring from a string with non-ASCII characters.There are few different ways we can return the portion of a string before the first occurrence of a character in PHP.Use the negative length to omit a length number of characters in the returned substring.The last character in the input string has an index of -1. Use the negative offset to extract a substring from the end of the string.Use the PHP substr() function to extract a substring from a string.The following defines a helper function that uses the mb_substr() function to extract a substring from a string:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |