Jump to content

Preg_replace Issues


maxudaskin

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/217268-preg_replace-issues/
Share on other sites

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);

 

Link to comment
https://forums.phpfreaks.com/topic/217268-preg_replace-issues/#findComment-1128284
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.