PHP | highlight_string() function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The highlight_string() function is an inbuilt function in PHP which is used to highlight the text string. It returns output in HTML text format. Syntax: highlight_string( $string, $return ) Parameters: This function accepts two parameters as mentioned above and described below: $string: It is the required parameter which specifies the text to be highlighted. $return: It is the optional parameter. If it is True then it provides a highlighted code as a string, instead of printing it on the screen. Return Value: If it is True then it returns highlighted code as a string, otherwise false on failure. Below programs illustrate the highlight_string() function in PHP. Program 1: php <?php highlight_string('Welcome to Geeksforgeeks'); ?> Output: <code><span style="color: #000000"> <span style="color: #0000BB"><?php phpinfo</span><span style="color: #007700">(); </span><span style="color: #0000BB">?></span> </span></code> Program 2: PHP <?php highlight_string('<?php // PHP Program to add two numbers function Add( $x, $y) { $sum = $x + $y; return $sum; } // Driver Code echo Add(15, 32); ?>') ?> Output: <code><span style="color: #000000"> <span style="color: #0000BB"> <?php<br /></span><span style="color: #FF8000"> // PHP Program to add two numbers<br /><br /> </span><span style="color: #007700">function </span><span style="color: #0000BB"> Add</span><span style="color: #007700">( </span><span style="color: #0000BB"> $x</span><span style="color: #007700">, </span><span style="color: #0000BB"> $y</span><span style="color: #007700">)<br />{<br /> </span> <span style="color: #0000BB">$sum </span><span style="color: #007700">= </span> <span style="color: #0000BB">$x </span><span style="color: #007700">+ </span> <span style="color: #0000BB">$y</span><span style="color: #007700">; <br /> <br /> return </span><span style="color: #0000BB">$sum</span><span style="color: #007700">;<br /> }<br /><br /> </span><span style="color: #FF8000"> // Driver Code<br /> </span><span style="color: #007700">echo </span> <span style="color: #0000BB">Add</span><span style="color: #007700"> (</span><span style="color: #0000BB">15</span><span style="color: #007700"> , </span><span style="color: #0000BB">32</span><span style="color: #007700"> );<br /></span><span style="color: #0000BB">?></span> </span></code> Reference: https://www.php.net/manual/en/function.highlight-string.php Comment More infoAdvertise with us Next Article PHP | highlight_file() Function S sarthak_ishu11 Follow Improve Article Tags : PHP Similar Reads PHP | highlight_file() Function The highlight_file() function is an inbuilt function in PHP which is used to highlight the syntax of file. The syntax is highlighted by using HTML tags. Syntax: highlight_file( $filename, $return ) Parameters: This function accepts two parameters as mentioned above and described below: $filename: It 2 min read PHP | highlight_file() Function The highlight_file() function is an inbuilt function in PHP which is used to highlight the syntax of file. The syntax is highlighted by using HTML tags. Syntax: highlight_file( $filename, $return ) Parameters: This function accepts two parameters as mentioned above and described below: $filename: It 2 min read PHP String Functions Strings are a fundamental data type in PHP, used to store and manipulate text. PHP provides a wide variety of built-in string functions. These functions perform various operations such as string transformations, character manipulations, encoding and decoding, and formatting, making string handling s 6 min read PHP strlen() Function The strlen() is a built-in function in PHP which returns the length of a given string.It calculates the length of the string including all the whitespaces and special characters. Syntax:strlen($string);Parameters: This parameter represents the string whose length is needed to be returned. Return Val 1 min read PHP strlen() Function The strlen() is a built-in function in PHP which returns the length of a given string.It calculates the length of the string including all the whitespaces and special characters. Syntax:strlen($string);Parameters: This parameter represents the string whose length is needed to be returned. Return Val 1 min read PHP strspn() Function The strspn() function is an in-built function in PHP which finds the length of the initial segment of a string consisting entirely of characters contained within a given list of characters passed as a parameter to the function. Syntax : strspn( $string, $charlist, $start, $length) Parameters : This 3 min read Like