maxudaskin Posted October 30, 2010 Share Posted October 30, 2010 Hey guys, Yet again I am stumped on preg_replace. I want to turn a string with flight plan waypoints into points on a map. I have the mapping down (thanks to Google), but I am having trouble converting a certain type of waypoint into what I want it. Pretty much, I need it to take the space out of this (D representing a digit, C representing a character [N, E, S, or W]) DDDDC DDDDDC, but not take the space out from between other waypoints (as I explode it into an array later on). Any idea what I'm doing wrong? --- Preg_replace code $d = "([0-9])"; $c = "([eEnNsSwW])"; $s = "([[:space:]])"; $format = "/" . $d . $d . $d . $d . $c . $s . $d . $d . $d . $d . $d . $c . "/"; $replace = "\1\2\3\4\5\7\8\9\10\11\12"; $route = $results['route']; $route = preg_replace($format, $replace, $route); Here's a sample of the full route VALLY1 VALLY WOLFO AR18 ETECK M202 UKOKA M202 MUNEY 4100N 06000W 4300N 05500W 4400N 05000W 4700N 04000W 4800N 03000W 4900N 02000W BEDRA NERTU GAPLI UL620 GIBSO OCK2E In the end, I'm going to also convert the textual coordinates into decimal coordinates for use with Google maps. Thank you ahead of time for your time and help Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 30, 2010 Share Posted October 30, 2010 Looks like a KMIA departure . . . Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted October 30, 2010 Author Share Posted October 30, 2010 Looks like a KMIA departure . . . Indeed... for the example, I'm using KMIA - EGLL... Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted October 30, 2010 Author Share Posted October 30, 2010 Here is my final solution, for those who may want to know. $format = '"([0-9][0-9][0-9][0-9][nNeEsSwW]) ([0-9][0-9][0-9][0-9][0-9][nNeEsSwW])"'; $replace = "\\1,\\2"; $route = $results['route']; $route = preg_replace($format, $replace, $route); Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 30, 2010 Share Posted October 30, 2010 Sweet. Sim, yes? 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.