Jump to content

strtoupper. 911 help


runei

Recommended Posts

Hello. Very new to php and im am trying to make a the input the user writes both in strlen() and

strtoupper(). The strlen works fine but how am im supposed to get all the letters in uppercase as well? I also want to remove the white space between words with the str_replace(), but as you can see it has gone horribly wrong with trying to get the letters in uppercase. I have been trying lots of things and i dont really know what i am doing lol. I would be grateful for any help? I am trying to call on the same variable with in the if-statement, not sure if thats even allowed  ???

 

Thx

runei

 

<html>
<body>
Max 20 characters.
<br>
<br>
<form action="streng.php" method="post">

Skriv noe: 
<input type="text" name="navn">

<input type="submit" value="Send" name="submit">
</form>

</body>
</html>

 

<?php 

echo $_POST['navn'];
$brukerinput = $_POST['navn'];
//$uppercase = $_POST['navn'];
//$brukerinput = strtoupper($_POST['navn']);

if (strlen($brukerinput)<= 20){ //&& strtoupper($brukerinput)){

echo ". Length of string is ".strlen($brukerinput); //&& strtoupper($brukerinput); //&& strtoupper($uppercase); //&& (isset($_POST['navn']));
}
else
{ 
echo ". To long string, type fewer than 20 characters.";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/122733-strtoupper-911-help/
Share on other sites

What's wrong with $brukerinput = strtoupper($_POST['navn']); ???

 

Since you've already assigned $_POST['navn'] to a variable it's a bit cleaner to do this:

 

$brukerinput = strtoupper($brukerinput);

 

//$uppercase = $_POST['navn']; is unnecessary. Also, what's the use of this:

//&& strtoupper($brukerinput); //&& strtoupper($uppercase); //&& (isset($_POST['navn']));  ???

Link to comment
https://forums.phpfreaks.com/topic/122733-strtoupper-911-help/#findComment-633791
Share on other sites

Thx for your reply DjMikeS, i now put in the following code but i cannot get i in uppercase..

 

<?php 

echo $_POST['navn'];
$brukerinput = $_POST['navn'];
$brukerinput = strtoupper($brukerinput);

if (strlen($brukerinput)<= 20){ 

echo ". Length of string is ".strlen($brukerinput); 
}
else
{ 
echo ". To long string, type fewer than 20 characters.";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/122733-strtoupper-911-help/#findComment-633806
Share on other sites

Well, I just copied your script and ran it on my webserver....

 

<?php 

$brukerinput = "ThISisJusTAtEst";
//$brukerinput = $_POST['navn'];
$brukerinput = strtoupper($brukerinput);

if (strlen($brukerinput)< 20){ 

echo ". Length of string is ".strlen($brukerinput); 
}
else
{ 
echo ". To long string, type fewer than 20 characters.";

}
echo $brukerinput;
?>

 

Outputs:

. Length of string is 15THISISJUSTATEST

 

Which is what you would expect....

Notice the removed = in <=. Just a < will do...

 

BTW: how do you know it's not uppercase? I don't see you echo'ing the value of $brukerinput anywhere..... ???

Link to comment
https://forums.phpfreaks.com/topic/122733-strtoupper-911-help/#findComment-633808
Share on other sites

You can include the html form code if you want.

But if you want to do that you'll need to tell php that it should only run the script if the form is submitted like so:

if (isset($_POST['submit'])) {
    //do yo thingy....
}
else {
    //show html form....
}

Link to comment
https://forums.phpfreaks.com/topic/122733-strtoupper-911-help/#findComment-633836
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.