forestpest Posted October 20, 2008 Share Posted October 20, 2008 <?php $message = $_GET['message']; //get message if(!isset($message)) //if message vraiable empty { echo 'wrong'; } else { //get message length $l = strlen($message); //find where ending zeros are $findme = '000000000000000'; $pos_zeros = stripos($message, $findme); if ($pos_zeros === false) { echo "The string '$findme' was not found in the string '$message'"; } $id = substr($message,0,15); //get id $year = substr($message,15,4); $month = substr($message,19,2); $day = substr($message,21,2); $hours = substr($message,23,2); $minutes = substr($message,25,2); $seconds = substr($message,27,2); $found_fs = substr($message,29,2); $fs = "fs"; $offset_until_zeros = ($l - $pos_zeros); echo 'offset until zeros =' . $offset_until_zeros; $data = substr($message,31,$offset_until_zeros); $ff = "ff"; echo 'length = ' . $l; echo $message; echo $data; } ?> input in browser is link_not_shown because it's an active url so please excuse?message=55901392696301120081019194525fs-0.1,+0.2,-4.3,+5.1,-5.5,ff,000000000000000 output is as follows offset until zeros =15 length = 74 message becomes 55901392696301120081019194525fs-0.1, 0.2,-4.3, 5.1,-5.5,ff,000000000000000 (plus signs are gone why?) $data = -0.1, 0.2,-4.3, where are the rest until the before the first 0? I should get $data = -0.1,+0.2,-4.3,+5.1,-5.5,ff, what is happening?????? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 a + is a special character in a url. make sure you use rawurlencode() around the value for message: <?php $msg = '55901392696301120081019194525fs-0.1,+0.2,-4.3,5.1,-5.5,ff,000000000000000'; $url = 'excuse?message='.rawurlencode($msg); print $url; ?> Quote Link to comment Share on other sites More sharing options...
forestpest Posted October 20, 2008 Author Share Posted October 20, 2008 Ok I was able to make the device send me the url without the + signs. url is created from a mobile device so it neeeded re-programming but still input in browser is http://secreturl?message=55901392696301120081019194525fs-0.1,0.2,-4.3,5.1,-5.5,ff,000000000000000 output is offset until zeros =15 length = 72 $message = 55901392696301120081019194525fs-0.1,0.2,-4.3,5.1,-5.5,ff,000000000000000 data = -0.1,0.2,-4.3,5 where's the rest until before the 1st zeero? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 20, 2008 Share Posted October 20, 2008 a Plus in a url stands for a space. excuse?message=55901392696301120081019194525fs-0.1,+0.2,-4.3,+5.1,-5.5,ff,000000000000000 $myStr = str_replace(' ','+',$_GET['message']); Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 you are calculating offset_until_zeros wrong: $offset_until_zeros = ($pos_zeros - 31); Quote Link to comment Share on other sites More sharing options...
forestpest Posted October 20, 2008 Author Share Posted October 20, 2008 solved!!!!! sorry I feel dumb it must be because I haven't been sleeping Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 on a side note, you can shorten this code up DRASTICALLY with preg_match. not sure how flexible it needs to be, but this works with your example: <?php //Removed all the GET stuff for testing $message = '55901392696301120081019194525fs-0.1,0.2,-4.3,5.1,-5.5,ff,000000000000000'; if(preg_match('/^(\d{15})(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})fs(.+?),0{15}$/',$message,$matches)){ list(,$id,$year,$month,$day,$hours,$minutes,$seconds,$data) = $matches; //Here all your variables should be set } ?> Quote Link to comment Share on other sites More sharing options...
philipolson Posted October 20, 2008 Share Posted October 20, 2008 Another problem is your code will never output "Wrong" because $message will be set 100% of the time (since you set it above) so I reckon you meant to use empty() or some other check there and not isset(). Or, isset() on the $_GET['message'] is fine too. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 Another problem is your code will never output "Wrong" because $message will be set 100% of the time (since you set it above) so I reckon you meant to use empty() or some other check there and not isset(). Or, isset() on the $_GET['message'] is fine too. i meant to point that out in my first post, but forgot. as per philipolson, it should be: if(empty($message)) //if message vraiable empty 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.