String Function in PHP

nl2br():

The nl2br() function adds the
tag if it finds the carriage return (n) in the text. If you text is long and at many places carriage return is present, even then the nl2br() tag will replace all the occurrence of the carriage return with
tag.

Here is the syntax of the nl2br() tag:

[php]
<?php
$myString ="Welcome to openshell blog.nnHere you can share & earn knowledge";
echo nl2br($myString);

?>
[/php]

ucfirst():

The ucfirst() function converts the first character of a string to uppercase.

Here is the syntax of the ucfirst() tag:

[php]
<?php
echo ucfirst("welcome to openshell");
?>
[/php]

ucwords():

The ucwords() function converts the first character of each word in a string to uppercase.

Here is the syntax of the ucwords() tag:

[php]
<?php
echo ucwords("welcome to openshell");
?>
[/php]

quotemeta():

The quotemeta() function adds backslashes in front of some predefined characters in a string. This function can be used to escape characters with special meanings, such as ( ), [ ], and * in SQL.

Here is the syntax of the quotemeta() tag:

[php]
<?php
$str = "Welcome to our blog. (Whether its useful?)";
echo quotemeta($str);
?>

[/php]

Permanent link to this article: https://blog.openshell.in/2011/08/string-function-in-php/

Leave a Reply

Your email address will not be published.