Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,170 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,289 people online right now. Registration is fast and FREE... Join Now!




conditioning text strings

 
Reply to this topicStart new topic

conditioning text strings

ghqwerty
29 Aug, 2008 - 08:54 AM
Post #1

D.I.C Regular
Group Icon

Joined: 8 Aug, 2008
Posts: 373



Thanked: 8 times
Dream Kudos: 25
My Contributions
ok so ive got a bit where the user has to add a number into a text field for a bet how do i make a code so that if the did 050 it would then say you bet 50 not you bet 050

This post has been edited by ghqwerty: 29 Aug, 2008 - 08:55 AM
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: Conditioning Text Strings
29 Aug, 2008 - 09:38 AM
Post #2

D.I.C Regular
Group Icon

Joined: 8 Aug, 2008
Posts: 481



Thanked: 32 times
My Contributions
There's probably a better way, but you could add 0 to the number to force it to be treated as a number:
CODE
<?php
$x=$_POST['URbet'];
if ($x > 0 ){
$x=$x+0;
echo "<br>You bet: ".$x."<br>";
}
?>
<html>
<form action="<?php echo $php_self ?>" method="post">
Please enter your bet: <input type="integer" size= 15 name="URbet" /><br>
<input type="submit" value="Submit" />
</form>
</html>


This post has been edited by CTphpnwb: 29 Aug, 2008 - 09:39 AM
User is offlineProfile CardPM
+Quote Post

ghqwerty
RE: Conditioning Text Strings
29 Aug, 2008 - 09:44 AM
Post #3

D.I.C Regular
Group Icon

Joined: 8 Aug, 2008
Posts: 373



Thanked: 8 times
Dream Kudos: 25
My Contributions
QUOTE(CTphpnwb @ 29 Aug, 2008 - 10:38 AM) *

There's probably a better way, but you could add 0 to the number to force it to be treated as a number:
CODE
<?php
$x=$_POST['URbet'];
if ($x > 0 ){
$x=$x+0;
echo "<br>You bet: ".$x."<br>";
}
?>
<html>
<form action="<?php echo $php_self ?>" method="post">
Please enter your bet: <input type="integer" size= 15 name="URbet" /><br>
<input type="submit" value="Submit" />
</form>
</html>




thanks its working now smile.gif
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Conditioning Text Strings
29 Aug, 2008 - 09:46 AM
Post #4

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 479



Thanked: 24 times
Dream Kudos: 350
My Contributions
how about using (int)$_POST['number'];
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: Conditioning Text Strings
29 Aug, 2008 - 10:02 AM
Post #5

D.I.C Regular
Group Icon

Joined: 8 Aug, 2008
Posts: 481



Thanked: 32 times
My Contributions
I knew there was a better way! wink2.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:06AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month