Hope you get my drift
how would i do this?!
Moderator: General Moderators
-
DynamiteHost
- Forum Commoner
- Posts: 69
- Joined: Sat Aug 10, 2002 5:33 pm
how would i do this?!
Say if I had $number, how would I scan it to see if the value started with a "0"? And if it didn't have a 0 at the beginning, how would I add one?
Hope you get my drift
Hope you get my drift
-
codewarrior
- Forum Commoner
- Posts: 81
- Joined: Wed Aug 07, 2002 1:28 pm
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
try
Code: Select all
if(strpos($number, "0") != "1"){
$number = "0".$number;
}You could use regular expression but it'll be slower:
Code: Select all
<?php
if(!ereg("^ї0]+ї0-9A-Za-z]*$",$string)) {
$string = "0".$string;
}
?>-
DynamiteHost
- Forum Commoner
- Posts: 69
- Joined: Sat Aug 10, 2002 5:33 pm
not in this case which is why that post makes absolutely no sense.
"^0" is all you needed in that exp
if you're trying to pad your numbers you could use str_pad (i'm not sure if that's what you're trying to get at, so it's just a thought)
"^0" is all you needed in that exp
if you're trying to pad your numbers you could use str_pad (i'm not sure if that's what you're trying to get at, so it's just a thought)
Code: Select all
$number = str_pad($number,"2","0",STR_PAD_LEFT);- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
-
DynamiteHost
- Forum Commoner
- Posts: 69
- Joined: Sat Aug 10, 2002 5:33 pm
i wasn't saying that it wasn't, i was just throwing that idea out incase he is trying to pad the hard way which is why i put that little disclaimer at the end there saying so.
w/o using strpos so it's a little faster
Code: Select all
if($numberї0] != 0) {
$number = "0$number";
}