How to get the position of character in a string in PHP ? Last Updated : 23 Jul, 2025 Suggest changes Share 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 Create Quiz G gottumukkalabobby Follow 0 Article Tags : Web Technologies PHP PHP-string PHP-function PHP-Questions +1 More Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like