Jump to content

[SOLVED] Parse text


johnadamson

Recommended Posts

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

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

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.