johnadamson Posted May 4, 2007 Share Posted May 4, 2007 HELP!! I have the following text 1d35m37.7s It is a longitude coordinate (dms). What I would like to do is parse the text so and put it into variables e.g. So that the result would be the following $d=1 $m=35 $s=37.7 The answer is probably staring me in the face but I cannot see it. I would appreciate any help. Quote Link to comment Share on other sites More sharing options...
DaveEverFade Posted May 4, 2007 Share Posted May 4, 2007 Ignore this comment... Turns out I don't know PHP Quote Link to comment Share on other sites More sharing options...
DaveEverFade Posted May 4, 2007 Share Posted May 4, 2007 Ok, well if the format doesn't change (ie it's the same amount or characters) you can use this: $text="1d35m37.7s"; $d= substr($text, 0, 1); // gets the first char $m=substr($text, 2, 2); // gets the 3rd and 4th chars $s=substr($text, 5, 4); // gets the rest Quote Link to comment Share on other sites More sharing options...
Eugene Posted May 4, 2007 Share Posted May 4, 2007 $text = "1d35m37.7s"; $ex = preg_split('/[a-z]{1}/i', $text); $d = $ex[0]; $m = $ex[1]; $s = $ex[2]; Quote Link to comment Share on other sites More sharing options...
johnadamson Posted May 4, 2007 Author Share Posted May 4, 2007 DaveEverFade...You are an absolute LEGEND!! That worked perfectly. Thank you very much. Quote Link to comment Share on other sites More sharing options...
johnadamson Posted May 4, 2007 Author Share Posted May 4, 2007 Also thank you Eugene. That also worked a treat!! Quote Link to comment Share on other sites More sharing options...
DaveEverFade Posted May 4, 2007 Share Posted May 4, 2007 I'd go with Eugene's as mine is restricted to that exact layout.. 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.