ccrevcypsys Posted December 14, 2007 Share Posted December 14, 2007 How would i be able to explode a phone number that looks like this (775)443-9864 this is what i have <?php $Number = $mainQuery[0]['OfficePhone']; $exploded = explode("-", $Number); ?> (<input type="text" name="Areacode" style="width:25px;" value="<?php echo $exploded[0]; ?>" />) <input type="text" style="width:25px;" name="FirstSet" value="<?php echo $exploded[1]; ?>" />-<input type="text" style="width:30px;" name="SecSet" value="<?php echo $exploded[2]; ?>" /> Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted December 14, 2007 Share Posted December 14, 2007 What format are you needing to put it in after exploding it? Quote Link to comment Share on other sites More sharing options...
ccrevcypsys Posted December 14, 2007 Author Share Posted December 14, 2007 well its for a form so the same format but i need to take out the 1. 775 2. 443 3. 9864 and the way the db is it looks like this (775)443-9864 Quote Link to comment Share on other sites More sharing options...
p2grace Posted December 14, 2007 Share Posted December 14, 2007 I wouldn't explode it. Instead I would do something like this: $input = "(123) 456-7890"; $replace = array("(",")"," ","-"); $clean = str_replace($replace,"",$input); // yielding 1234567890 $areacode = substr($input,0,3); // yielding the area code (123) $next_three = substr($input,3,3); // yielding first three digits (456) $last_four = substr($input,7,4); // yielding last four (7890) This will remove all instances of "(" or ")" or " " or "-" with nothing, yielding a clean str of integers. Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted December 14, 2007 Share Posted December 14, 2007 Try this. It breaks the area code, next three numbers and last four numbers into a separate variable. <? $date = "(775)443-9864"; $d = explode("-", $date); //get rid of the dash echo $d[0]; //output (775)443 echo "<br>"; echo $d[1]; //output 9864 echo "<br>"; $v = $d[0]; //assigns (775)443 to another variable to explode next $t = explode("(", $v); //get rid of the first ( echo "<br>"; echo $t[1]; //output 775)443 $s = $t[1]; //assigns 775)443 to another variable to explode next $a = explode(")", $s); //get rid of the first ) echo "<br>"; print_r($a); //output $a[0] = 775 and $a[1] = 443 //then you can combine the variables to any format you need with implode //hope this is what you needed. Lots of steps. ?> Quote Link to comment Share on other sites More sharing options...
ccrevcypsys Posted December 14, 2007 Author Share Posted December 14, 2007 well i figured a way out that isnt like 1000 lines of code and here it is incase anyone needs it <?php $OfficePhone = ereg_replace(') ',')-',$mainQuery[0]['OfficePhone']); $exploded = explode("-", $OfficePhone); ?> It replaces the ') ' with ')-' so taht when i explode it the () are still in tact for the area code. But thanks guys. Hows that for ezy lol lol Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.