Str to lower is used to convert total string to lower case
<?php
$str="My name is KHAN";
$str=strtolower($str);
echo $str;
?>
my name is khan
strtoupper is used to convert total string to upper case
<?php
$str="My name is KHAN";
$str=strtoupper($str);
echo $str;
?>
MY NAME IS KHAN
Ucfirst – used to convert string starting letter is upper
case
<?php
$str="my name is KHAN";
$str=ucfirst($str);
echo $str;
?>
My name is KHAN
Lcfirst is used to convert first letter of the string to
lower case
<?php
$str="MY name IS KHAN";
$str=lcfirst($str);
echo $str;
?>
mY name IS KHAN
ucwords used to convert every ist letter of word
<?php
$str="my name is Sonoo jaiswal";
$str=ucwords($str);
echo $str;
?>
My Name Is Sonoo Jaiswal
Strrev – used to convert each word in reverese of this
string
<?php
$str="my name is Sonoo jaiswal";
$str=strrev($str);
echo $str;
?>
lawsiaj oonoS si eman ym
strlen
<?php
$str="my name is Sonoo jaiswal";
$str=strlen($str);
echo $str;
?>
24
Addc
slashes
Used
to write slash at required letter
<?php
$str="Welcome to JavaTpoint";
echo "Your String : ".$str;
echo "<br>"."By using 'addcslashes()' method your string: ".addcslashes($str,'T')."<br>";
?>
Your String : Welcome to JavaTpoint
By using 'addcslashes()' method your string: Welcome to Java\Tpoint
Addslashes()
It
will add slashes at at every single quote and double quote
<?php
$str = 'What does "WHO" mean?';
echo "Your string is :".$str;
echo "<br>"."By using addslashes() function the result is".addslashes($str);
?>
Your string is :What does "WHO" mean?
By using addslashes() function the result isWhat does \"WHO\" mean?
<?php
$str = "Who's the father of PHP?";
echo $str . " This is not safe in a database query.<br>";
echo addslashes($str) . " This is safe in a database query.";
?>
Who's the father of PHP? This is not safe in a database query.
Who\'s the father of PHP? This is safe in a database query.
It will
not add slashes if we write like that
<?php
$str = "Wow' PHP?";
eval("echo '" . addslashes($str) . "';");
?>
Wow' PHP?
Is The Father of PHP\'Rasmus?
NUMBER
CONVERSATION METHODS
How
to convert bin to hexa
<?php
$str = "Hello world!";
echo "Your Hexadecimal Value is
".bin2hex($str) . "<br>";
?>
Your Hexadecimal Value is
48656c6c6f20776f726c6421
How to convert hexa to binary using pack
method
Pack will convert first given h means hexa
to binary
<?php
$str
= "Hello world!";
echo
"Your Hexadecimal Value is ".bin2hex($str) .
"<br>";
echo
pack("H*","48656c6c6f20776f726c6421") .
"<br>";
?>
Your Hexadecimal Value is
48656c6c6f20776f726c6421
Hello world!
Hello world!
Bin2hex
Bindec
Dechex
How
to remove some words in string
Chop
will cut which we specify
1. <?php
2. $str = "Hello World!";
3. echo "Your string is :".$str."<br>";
4. echo "By using 'chop()' Functions is your string is: ".chop($str,"World!");
5. ?>
Your string is :Hello World!
By using 'chop()' Functions is your string is: Hello
We
given ascii character , it will convert to alphabets in single digit
1. <?php
2. $char =052;
3. echo "Your character is :".$char;
4. echo "<br>"."By using 'chr()' function your value is: ".chr($char); // Octal Value
5. ?>
Your character is :42
By using 'chr()' function your value is: *
Chunk_split
How
to add some characters after every 6 th or required
1. <?php
2. $str = "Hello javatpoint!";
3. echo "Your string is:".$str;
4. echo "By using 'chunk_split()' function your string is:".chunk_split($str,6,"...");
5. ?>
Hello ...javatp...oint!...
Your string is: Hello
By using 'chunk_split()' function your string is: H.e.l.l.o.
How to decode ur string
1. <?php
2. $str ="*:F%V851P;VEN=``` ` "; // javatpoint
3. echo "Your Decode string is :".$str;
4. $encodeString ="<br>"."By using 'convert_uudecode()' function your encoded string is : ". convert_uudecode($str);
5. echo $encodeString . "<br>";
6. ?>
Your Decode string is :*:F%V851P;VEN=``` `
By using 'convert_uudecode()' function your encoded string is : javaTpoint
How to encode the string
1. <?php
2. // encode the string
3. $str2 = "I love My India";
4. echo "Your Decoded string is :".$str2;
5. $uuencodeString ="<br>"."By using 'convert_uuencode()' function your encoded string is : ". convert_uuencode($str2);
6. echo $uuencodeString . "<br>";
7. ?>
Your Decoded string is :I love My India
By using 'convert_uuencode()' function your encoded string is : /22!L;W9E($UY($EN9&EA `
Explode
It sepereated by sepearaetor and third parameter tells upto
1. <?php
2. // original string
3. $Original_str = "Hello, we are here to help you.";
4.
5. // Passed zero
6. print_r (explode (" ",$Original_str, 0));
7. // Passed positive value
8. print_r (explode (" ",$Original_str, 4));
9. // Passed negative value
10. print_r (explode (" ",$Original_str, -3));
11. ?>
Array ( [0] => Hello, we are here to help you. ) Array ( [0] => Hello, [1] => we [2] => are [3] => here to help you. ) Array ( [0] => Hello, [1] => we [2] => are [3] => here )
Upto zero it splits
Html entities
It will not take html, it removes html
1. <?php
2. $str = '<a href="https://www.javatpoint.com">Go to javatpoint.com</a>';
3. echo htmlentities($str);
4. ?>
Go to javatpoint.com
1. <?php
2. $str = "Hello PHP : 'E=MC?'";
3. echo htmlentities($str, ENT_COMPAT); // Will only convert double quotes
4. echo "<br>";
5. echo htmlentities($str, ENT_QUOTES); // Converts double and single quotes
6. echo "<br>";
7. echo htmlentities($str, ENT_NOQUOTES); // Does not convert any quotes
8. ?>
Hello PHP : 'E=MC²'
Hello PHP : 'E=MC²'
Hello PHP : 'E=
How to join arrays
1. <?php
2. $input_arr = array ('Noida', 'Delhi', 'Gurugram');
3. //join with comma and space separator
4. $comma_separation = implode (", ", $input_arr);
5. echo $comma_separation;
6.
7. echo "</br>";
8. //join without separator
9. print_r (implode ($input_arr));
10. ?>
Noida, Delhi, Gurugram
NoidaDelhiGurugram
1. <?php
2. $input_arr1 = array ('Hello', 'everyone!');
3. $input_arr2 = array ('One' => 'Welcome', 'Two' => 'to', 'Three' => 'Javatpoint');
4.
5. //join both array elements
6. echo implode(' ', $input_arr1), ' / ', implode(' ', $input_arr2);
7. ?>
Hello everyone! / Welcome to Javatpoint
How to add sepearators to array to string
1. <?php
2. $arr = array('Hello','PHP','Join','Function');
3. echo join(" ",$arr)."<br>";
4. ?>
Hello PHP Join Function
1. <?php
2. $arr = array('Hello','PHP','Join','Function');
3. echo join("+",$arr)."<br>";
4. ?>
Hello+PHP+Join+Function
1. <?php
2. $arr = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10');
3. echo join('<br>', $arr);
4. ?>
1
2
3
4
5
6
7
8
9
10
- ucfirst() : It is
used to convert first character of a string to uppercase.
- ucwords() : It is
used to convert first character string to uppercase.
- strtoupper() : It is
used to convert a string to uppercase.
- strtolower() : It is
used to convert a string to lowercase.
PHP String
localeconv() Function
The localeconv() function
is the in-built function of PHP. It is used to get numeric information. This
function returns an array which contains local numeric and monetary formatting
information. This function is a non-parameterized function, so
we do not need to pass anything in this function.
Syntax
The basic syntax of the
localeconv() function of PHP is:
1.
localeconv();
Parameter
1. ?php
2. setlocale(LC_MONETARY,"US");
3. $localeinfo =localeconv();
4. print_r($localeinfo);
5. ?>
Array
(
[decimal_point] => .
[thousands_sep] => ,
[int_curr_symbol] => USD
[currency_symbol] => $
[mon_decimal_point] => .
[mon_thousands_sep] => ,
[positive_sign] =>
[negative_sign] => -
[int_frac_digits] => 2
[frac_digits] => 2
[p_cs_precedes] => 1
[p_sep_by_space] => 0
[n_cs_precedes] => 1
[n_sep_by_space] => 0
[p_sign_posn] => 3
[n_sign_posn] => 0
[grouping] => Array
(
[0] => 3
)
[mon_grouping] => Array
(
[0] => 3
)
)
Php itrim
1. <?php
2. $str = " Hello PHP!";
3. echo "Without ltrim() Function: " . $str;
4. echo "<br>";
5. echo "With ltrim() function : " . ltrim($str);
6. ?>
Without ltrim() Function: Hello PHP!
With ltrim() function : Hello PHP!
No comments:
Post a Comment