The substr() and strpos() function is used to remove portion of string after certain character.
strpos() function: This function is used to find the first occurrence position of a string inside another string. Function returns an integer value of position of first occurrence of string. Function treats upper-case and lower-case characters differently.
strpos( original_string, search_string, start_pos )
Return Value: This function returns an integer value which represents the index of original_str where the string search_str first occurs.
substr() function: The substr() function is an inbuilt function in PHP is used to extract a specific part of string.
substr( string_name, start_position, string_length_to_cut )
Return Value: Returns the extracted part of the string if successful otherwise FALSE or an empty string on failure.
Here are few examples.
Below examples use substr() and strpos() function to remove portion of string after certain character.
GeeksForGeeks is the best platform. GeeksForGeeks
computer science portal for geeks computer science portal
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.