1. Str_replace
$str = "You should eat fruits, vegetables, and fiber every day.";$healthy = array("fruits", "vegetables", "fiber");$yummy = array("pizza", "beer", "ice cream");$new_str = str_replace($healthy, $yummy, $str);
2. expode : Convert a String into array by separator
$str = "You should eat fruits";
$array = explode(' ', $str);
$array = ['You','should','eat','fruits']
3. str_split : Convert a String into array by separating every word
$str = "azad";
$array = str_split($str);
$array = ['a','z','a','d'];
4. strlen :length of string
$str = "php str";
$length = strlen($str);
Output => 7
5. str_word_count :Count no of words in string
$str = "php str";
$wordCount = str_word_count($str);
Output=> 2
6. strrev : Convert a String into reverse order
$str = "*azad!";
$revStr = strrev($str);
$revStr = "!daza*";
7. strpos :Search starting of word from string
$str = "*azad! is a nationalist";
$foundOn = strpos($str,"is");
$foundOn = 7;
$str = "You should eat fruits, vegetables, and fiber every day.";$healthy = array("fruits", "vegetables", "fiber");$yummy = array("pizza", "beer", "ice cream");$new_str = str_replace($healthy, $yummy, $str);
2. expode : Convert a String into array by separator
$str = "You should eat fruits";
$array = explode(' ', $str);
$array = ['You','should','eat','fruits']
3. str_split : Convert a String into array by separating every word
$str = "azad";
$array = str_split($str);
$array = ['a','z','a','d'];
4. strlen :length of string
$str = "php str";
$length = strlen($str);
Output => 7
5. str_word_count :Count no of words in string
$str = "php str";
$wordCount = str_word_count($str);
Output=> 2
6. strrev : Convert a String into reverse order
$str = "*azad!";
$revStr = strrev($str);
$revStr = "!daza*";
7. strpos :Search starting of word from string
$str = "*azad! is a nationalist";
$foundOn = strpos($str,"is");
$foundOn = 7;
No comments:
Post a Comment