runei Posted September 4, 2008 Share Posted September 4, 2008 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 More sharing options...
DjMikeS Posted September 4, 2008 Share Posted September 4, 2008 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 More sharing options...
runei Posted September 4, 2008 Author Share Posted September 4, 2008 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 More sharing options...
DjMikeS Posted September 4, 2008 Share Posted September 4, 2008 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 More sharing options...
runei Posted September 4, 2008 Author Share Posted September 4, 2008 Nice, it does work as long as i dont include the html form. thanks again I did echo $brukerinput now and it worked Link to comment https://forums.phpfreaks.com/topic/122733-strtoupper-911-help/#findComment-633820 Share on other sites More sharing options...
DjMikeS Posted September 4, 2008 Share Posted September 4, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.