The most viewed items
<?php
$text = 'I am Thet Naing Win.';
for($count = 1; $count <= 10; $count++){
echo $count. ' '.$text. '!</br>';
}
?>
<?php
$food = array('Healthy'=>array('Salad', 'Milk', 'Coconet', 'Ground_nut'),
'Unhealthy'=>array('Alcohol', 'Beer', 'Ice_cream'));
foreach($food as $element => $inner_element){
echo '</br><strong>'.$element.'</strong></br>';
foreach($inner_element as $item){
echo $item.'</br>';
}
}
?>
$date = 'Sunday';
switch($date){
case 'Saturday';
case 'Sunday';
echo 'It is weekend!';
break;
default;
echo 'It is not weekend day!';
break;
}
?>
<?php
$num1 = 30;
$num2 = 40;
if($num1 > $num2){
echo 'Num1 is greater than Num2!';
} else if($num1 == $num2){
echo 'Num1 and Num2 are equal!';
}else{
echo 'Num2 is greater than Num1!';
}
?>
<?php
$string = 'I am thet naing win';
$find = array('thet', 'naing', 'win');
$replace = array('THET', 'NAING', 'WIN');
$string_new = str_replace($find, $replace, $string);
echo $string_new;
?>
<?php
$string = 'I am Thet Naing Win. This is PHP Testing and Word position Test. If you are insterested in PHP, please join us!';
$find = 'T';
$find_length = strlen($find);
$offset = 1;
while ($strpos = strpos($string, $find, $offset)){
echo 'The Character <strong>'.$find. '</strong> is found at '.$strpos.'.</br>';
$offset = $strpos + $find_length;
}
?>
We can change all characters to lower case by using strtolower. The following code is an example.
<?php
$string = 'I am ThEt NainG WiN!';
$string_low = strtolower($string);
echo $string_low;
?>
We can also change all characters to upper case by using strtoupper. The following is an example.
<?php
$string = 'I am ThEt NAInG win!';
$string_up = strtoupper($string);
echo $string_up;
?>
<?php
$string = 'I am Thet Naing Win.';
$string_trimmed = rtrim($string);
echo $string_trimmed;
?>
<?php
$string = 'I am Thet Naing Win';
$string_reversed = strrev($string);
echo $string_reversed;
?>
<?php
$string = 'I am Thet Naing Win and who are you?';
$string_word_count = str_word_count($string, 1);
print_r($string_word_count);
?>
<?php
$string = 'I am Thet Naing Win';
$strlen = strlen($string);
echo $strlen;
?>
Write the following code and save it as info.php in C > xampp > htdoc.
<?php
phpinfo();
?>
Open Web Browser and type localhost/info.php in it and press Enter. Then, you will see the php version as the below picture.