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. Link to comment https://forums.phpfreaks.com/topic/49980-solved-parse-text/ 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 Link to comment https://forums.phpfreaks.com/topic/49980-solved-parse-text/#findComment-245361 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 Link to comment https://forums.phpfreaks.com/topic/49980-solved-parse-text/#findComment-245372 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]; Link to comment https://forums.phpfreaks.com/topic/49980-solved-parse-text/#findComment-245375 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. Link to comment https://forums.phpfreaks.com/topic/49980-solved-parse-text/#findComment-245376 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!! Link to comment https://forums.phpfreaks.com/topic/49980-solved-parse-text/#findComment-245377 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.. Link to comment https://forums.phpfreaks.com/topic/49980-solved-parse-text/#findComment-245384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.