Wednesday, February 16, 2011

Modify Case-PHP

Assalamu'alaikum and selamat sejahtera

So,for today we will learn on how to modify your string variable.For example,if we enter the input like this:"rock star" and we want the PHP to modify this input,to be like this :"Rock Star" or  "ROCK STAR".Okey,here is the code:

<html>
<head>
<title>Lessons for Changing Letter Case</title>


<?PHP

if (isset($_POST['Submit1'])) {

$full_name = $_POST['user_name'];
$full_name = ucwords($full_name);

print($full_name);

}

?>

</head>

<body>


<FORM NAME ="form1" METHOD ="POST" ACTION ="">

<Input type = 'text' Name ='user_name' value ="input name">
<P>
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "enter">
</FORM>

</body>
</html>

Here is the explainatio,so the new code for this lesson is:

$full_name = ucwords($full_name);

So,ucwords() function will take the $full_name(make sure that this variable's type is string) as its parametre,and modify tthis variable.For example,$full_name="rock star",so the ucwords($full_name) will modify $full_name as this variable has become the input for this function,finally,$full_name="Rock Star".

Besides,we also another function:


$full_ name=strtoupper($full_ name);
$full_ name=strtolower($full_ name);
$full_ name = ucfirst($full_ name);


test this function!if you want to know more...


N/NOTE:lol

No comments:

Post a Comment