String
A collection of characters, special symbols or alphanumeric known as string, It is used in every programming language, it is defined under single qoutes ' ' or under double qoutes " ". Datatype of string is char , varchar(2) etc
example : $str = "Hello America";
PHP String Functions
In php there are predefined functions to perform various operation on string. string functions doesn't require any setup to run. Suppose if we want to count the character in the string we have strlen(). strlen() will count the number of character containing init.
Some String functions
1. chop()
It removes the right side character from string
example :
<?php
$str = "Guide php";
echo $str = "Guide php";
echo chop($str, "php");
?>
output :
Guide php
Guide
2. explode()
It convert String to array
$str = "Guide php";
print_r(explode($str));
output :
Array ( [0] => Guide [1] => php)
3. implode()
It converts array to string
$arr = array("Guide","php");
echo implode(" ", $arr);
output :
Guide php
A collection of characters, special symbols or alphanumeric known as string, It is used in every programming language, it is defined under single qoutes ' ' or under double qoutes " ". Datatype of string is char , varchar(2) etc
example : $str = "Hello America";
PHP String Functions
In php there are predefined functions to perform various operation on string. string functions doesn't require any setup to run. Suppose if we want to count the character in the string we have strlen(). strlen() will count the number of character containing init.
Some String functions
1. chop()
It removes the right side character from string
example :
<?php
$str = "Guide php";
echo $str = "Guide php";
echo chop($str, "php");
?>
output :
Guide php
Guide
2. explode()
It convert String to array
$str = "Guide php";
print_r(explode($str));
output :
Array ( [0] => Guide [1] => php)
3. implode()
It converts array to string
$arr = array("Guide","php");
echo implode(" ", $arr);
output :
Guide php
4. ltrim()
Using this function we can remove left side character of string
$str = "Guide php";
echo $str;
echo "<br/>";
echo ltrim($str,"Guide");
output :
Guidephp
php
5. rtrim()
Using this function we can remove right character from a string
$str = "Guide php";
echo $str;
echo "<br/>";
echo rtrim($str,"php");
output :
Guide php
Guide
No comments: