Jump to content

Output Period in preg_replace


maxudaskin

Recommended Posts

I have the current code:

$coord = preg_replace('"([0-9]{2}|[0-9]{3})([0-9]{2})([nNeS])([0-9]{3})([0-9]{2})([eEsW])"', '\\1\.\\2 \\3,\\4\.\\5 \\6', $coord);
	$coord = explode(',', $coord);

	if(sizeof($coord) < 2) {
		return 'ERROR';
	}

	$coord[0] = explode(' ', $coord[0]);
	$coord[1] = explode(' ', $coord[1]);

	$latt = ($coord[0][1] == 'N') ? $coord[0][0] : '-' . $coord[0][0];
	$long = ($coord[1][1] == 'E') ? $coord[1][0] : '-' . $coord[1][0];

	return $latt . ',' . $long;

 

That I want to return \\1.\\2 \\3,\\4.\\5 \\6 where the periods output as themselves. Unfortunately, it's not working as I expected.

 

Thank you for your time.

Link to comment
https://forums.phpfreaks.com/topic/217277-output-period-in-preg_replace/
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.