How to get the position of character in a string in PHP ? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we will get the position of the character in the given string in PHP. String is a set of characters. We will get the position of the character in a string by using strpos() function. Syntax: strpos(string, character, start_pos) Parameters: string (mandatory): This parameter refers to the original string in which we need to search the occurrence of the required string.character (mandatory): This parameter refers to the string that we need to search.start_pos (optional): Refers to the position of the string from where the search must begin. Return Value: It returns the index position of the character. Example 1: PHP Program to get the position of particular character in the given string. PHP <?php // Consider the string $str1 = "Hello geeks for geeks"; // Get the position of 'f' character echo strpos($str1, 'f'); echo "\n"; // Get the position of 'H' character echo strpos($str1, 'H'); echo "\n"; // Get the position of 'l' character echo strpos($str1, 'l'); echo "\n"; // Get the position of ' ' space echo strpos($str1, ' '); ?> Output12 0 2 5 Example 2: PHP <?php // Consider the string $str1 = "Hello geeks for geeks"; // Get the position of 'f' character // starts from 5th index echo strpos($str1, 'f', 5); echo "\n"; // Get the position of 'H' character // starts from 8th index // No output since H is present at 1st // position, we started from 8th position echo strpos($str1, 'H', 8); ?> Output12 Comment More infoAdvertise with us Next Article How to read each character of a string in PHP ? G gottumukkalabobby Follow Improve Article Tags : Web Technologies PHP PHP-string PHP-function PHP-Questions +1 More Similar Reads How to get the last character of a string in PHP ? In this article, we will find the last character of a string in PHP. The last character can be found using the following methods.Using array() Method: In this method, we will find the length of the string, then print the value of (length-1). For example, if the string is "Akshit" Its length is 6, in 2 min read How to remove the first character of string in PHP? Remove the very first character of a given string in PHP Examples: Input : GeeksforgeeksOutput : eeksforgeeksInput :, Hello geek!Output : Hello geek!Explanation:In PHP to remove characters from the beginning we can use ltrim but in that, we have to define what we want to remove from a string i.e. re 3 min read How to remove the first character of string in PHP? Remove the very first character of a given string in PHP Examples: Input : GeeksforgeeksOutput : eeksforgeeksInput :, Hello geek!Output : Hello geek!Explanation:In PHP to remove characters from the beginning we can use ltrim but in that, we have to define what we want to remove from a string i.e. re 3 min read How to remove the first character of string in PHP? Remove the very first character of a given string in PHP Examples: Input : GeeksforgeeksOutput : eeksforgeeksInput :, Hello geek!Output : Hello geek!Explanation:In PHP to remove characters from the beginning we can use ltrim but in that, we have to define what we want to remove from a string i.e. re 3 min read How to read each character of a string in PHP ? A string is a sequence of characters. It may contain integers or even special symbols. Every character in a string is stored at a unique position represented by a unique index value. Here are some approaches to read each character of a string in PHPTable of ContentUsing str_split() method - The str_ 4 min read How to get string between two characters in PHP ? A string is a sequence of characters stored in the incremental form in PHP. A set of characters, one or many can lie between any two chosen indexes of the string. The text between two characters in PHP can be extracted using the following two methods : Table of ContentUsing substr() Method: Using fo 4 min read Like