PHP | highlight_string() function
Last Updated :
06 Aug, 2018
Improve
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:
php
Output:
PHP
Output:
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.
<?php
highlight_string('Welcome to Geeksforgeeks');
?>
<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
highlight_string('<?php
// PHP Program to add two numbers
function Add( $x, $y)
{
$sum = $x + $y;
return $sum;
}
// Driver Code
echo Add(15, 32);
?>')
?>
<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