PHP String Functions
PHP String Functions :
1.
Strlen(string) : used to find length of a string.
2.
Str-replace(): used to replace a part of
a string with another string and is case sensitive.
Str-replace(what
string, new string, source string[,no of replacements occure]);
3.
Str-ireplace() : case – in –sensitive
search and replace using array of strings.
Str-ireplace(find,replace,source
string,count)
4.
Trim() : function used for removing
empty space from both sides of a string.
Trim(string)
Ltrim(string)
Rtrim(string)
5.
Strrev(string) : function used for
reversing a string.
6.
Adding two or more strings in php. .
.=
<?php
$str
= "india tech";
echo
"size=". strlen($str)."<br>";
$str
="Html is used for designing a webpage ,html is a part of webpage";
$str1
= str_replace("HTML","PHP" ,$str, $c);
echo
$str1."<br>";
echo
"no of replacements=".$c."<br>";
$str
= "india tech";
$str1
= trim($str);
echo
$str1."--". strlen($str1)."<br>";
echo
strrev($str)."<br>";
$a
= 11;
$b=22;
$c=$a.$b;
echo
$c."<br>";
?>
OutPut:
size=10
Html
is used for designing a webpage ,html is a part of webpage
no
of replacements=0
india
tech--10
hcet
aidni
1122
7.
Strstr() : searching for the first occurance
of a string inside another string ; case sensitive search.
8.
Stristr() : searching for the first occurance of a string
inside another string ; Case insensitive search.
Stristr(sourcestring,
search string);
9.
nl2br(string) : function used to add line break(<br>)
inside a string in place of carriage returns(\n , \r)[new line break]
10.
str_split() : function used for breaking
a string to form array.
Str_split(string[,length]);
Where
the length arguments is optional that specifies the length of each array element
.
Default
is / .
<?php
$str
= "india is my country";
$search
= strstr($str,"is");
echo
$search."<br>";
$str
= "india\n technologies\r private\n";
echo
nl2br($str)."<br><br>";
$str
= "indian Technologies";
$data
= str_split($str);
print_r($data);
echo
"<br><br>";
$data
= str_split($str,3);
print_r($data);
?>
OutPut :
is
my country
india
technologies
private
Array
( [0] => i [1] => n [2] => d [3] => i [4] => a [5] => n [6]
=> [7] => T [8] => e [9] => c [10] => h [11] => n [12] =>
o [13] => l [14] => o [15] => g [16] => i [17] => e [18] => s
)
Array
( [0] => ind [1] => ian [2] => Te [3] => chn [4] => olo [5]
=> gie [6] => s )
0 comments:
Post a Comment