PHP PROGRAMS
DATAFETCH.HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> </title>
</head>
<body>
<form method="post"action="nameShort.php">
<label>Enter name: </label>
<input type="text" name="str1" id="str1">
<input type="submit" name="submit" id="Submit">
</form>
</body>
</html>
nameShort.php
<?php
$str = $_REQUEST['str1'];
// echo strlen($str);
$fstr = array();
$ws = true;
for($i=0; $i< strlen($str); $i++){
if($str[$i] == ' ')
{
$ws=true;
}
else if($str[$i]!= ' ' && $ws==true)
{
array_push($fstr,$str[$i]);
$ws = false;
}
}
for($i=0; $i<sizeof($fstr) ; $i++){
echo $fstr[$i];
}
?>
<!-- Vinay Apte as Prabhakarna Sripalawardhana Atapattu Jayasuriya Laxmansriramkrishna Shivavenkata Rajasekara Sriniwasana Trichipalli Yekya Parampeel Parambatur Chinnaswami Muthuswami Venugopal Iyer -->
Word Change.php
<?php
// Take a Sentence "Apple is a fruit. Output will print "elppA is a tiurf. only first and last word will reverse
$str = "Apple is a fruit";
$stra = explode(' ',$str);
$f= $stra[0];
$f = strrev($f);
$l = $stra[count($stra)-1];
$l = strrev($l);
echo $f." ".implode(" ",array_slice($stra,1,2))." ".$l;
?>
Comments
Post a Comment