PHP | highlight_string() function Last Updated : 06 Aug, 2018 Comments Improve Suggest changes 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: http://php.net/manual/en/function.highlight-string.php Comment More infoAdvertise with us Next Article PHP | highlight_string() function sarthak_ishu11 Follow Improve Article Tags : PHP Similar Reads PHP | is_string() Function The is_string() function is an inbuilt function in PHP which is used to check whether the given value is a string or not. Syntax: bool is_string( mixed $var ) Parameters: This function accepts one parameter as mentioned above and described below: $var: It contains the value that need to check. Retur 1 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 | Imagick __toString() Function The Imagick::__toString() function is an inbuilt function in PHP which is used to return the image as a string. This function will only return a single image and should not be used for Imagick objects containing multiple images. Syntax: string Imagick::__toString( void ) Parameters:This function doe 1 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 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 PHP mb_strlen() Function The mb_strlen() is an inbuilt PHP function that returns the string length in an integer. Syntax: mb_strlen($string, $encoding ): intParameters: This function accepts 2 parameters that are described below: $string: The string parameter whose lengths need to be determined. It is a required parameter.$ 1 min read PHP trim() Function The trim() function in PHP is an inbuilt function which removes whitespaces and also the predefined characters from both sides of a string that is left and right. Related Functions: PHP | ltrim() Function PHP | rtrim() Function Syntax: trim($string, $charlist) Parameters:The function accepts one man 2 min read PHP | str_ireplace() Function The str_ireplace() is a built-in function in PHP and is used to replace all the occurrences of the search string or array of search strings by replacement string or array of replacement strings in the given string or array respectively. This function performs the search in a case-insensitive manner. 3 min read PHP iconv_strlen() Function The iconv_strlen() is an inbuilt function in PHP that is used to calculate the length of a string. It is very useful when your working string is encoded in a different character set, as it can accurately determine the length regardless of the encoding. Syntax:iconv_strlen(string $string, ?string $en 2 min read Like