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
- How to select ID that starts with certain character using jQuery ?
- How to change state continuously after a certain amount of time in React?
- How to check if URL contain certain string using PHP?
- How to insert new row at a certain index in a table in jQuery ?
- How to check an element has certain CSS style using jQuery ?
- How to select a div with a certain class using jQuery ?
- How to remove the first character of string in PHP?
- How to Remove Special Character from String in PHP ?
- How to add space (" ") after an element using :after selector in CSS ?
- Removing occurrences of a specific character from end of a string in PHP
- Remove new lines from string in PHP
- How to remove extension from string in PHP?
- How to remove line breaks from the string in PHP?
- How to remove all non-printable characters in a string in PHP?
- How to remove all leading zeros in a string in PHP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.