Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

What can I do instead??

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

What can I do instead??

Postby rellison » Tue Mar 05, 2013 6:13 am

I use the following to pull data from a string of characters.

Code: Select all
if ($s = stristr($string,"<QSO_DATE"))
   {
   $values = $s, "<QSO_DATE:%d>%s ", $length,$qso_data['Date']);
   if ($values != 2)
   sscanf ($s, "<QSO_DATE:%d:%c>%s ", $length,$dummy,$qso_data['Date']);
         }


The text usually looks like this:
<CALL:4>WM4Q <QSO_DATE:8:D>19870801 <TIME_ON:4>1806 <BAND:3>10M <MODE:3>SSB <RST_SENT:2>59 <QSL_SENT:1>Y <QSL_SENT_VIA:1> E<EOR>
<CALL:6>ON4AMT <QSO_DATE:8:D>19891209 <TIME_ON:4>1548 <BAND:3>10M <MODE:3>SSB<RST_SENT:2>59 <QSL_SENT:1>Y <QSL_SENT_VIA:1>E <EOR>
<CALL:6>IK3ORD <QSO_DATE:8:D>19901208 <TIME_ON:4>1339 <BAND:3>10M <MODE:3>SSB <RST_SENT:2>59 <QSL_SENT:1>Y <QSL_SENT_VIA:1> E<EOR>
Note the spaces separates the data.

But some of the text that needs to be processed comes in like this with no spaces in between data.
<CALL:6>OT4AMT<QSO_DATE:8:D>19901208<TIME_ON:4>1450<BAND:3>10M<MODE:3>SSB<RST_SENT:2>59<QSL_SENT:1>Y<QSL_SENT_VIA:1>E<EOR>
<CALL:6>WD6DGS<QSO_DATE:8:D>19901208<TIME_ON:4>1959<BAND:3>10M<MODE:3>SSB<RST_SENT:2>59<QSL_SENT:1>Y<QSL_SENT_VIA:1>E<EOR>

When data comes like that the routine above bombs out. what can I use in place of the sscanf ( that would let me separate out the data with either a space or no space?? I know some PHP but not a lot so if someone can explain what to use I would be appreciated..

Rick
rellison
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Aug 03, 2011 3:00 pm

Re: What can I do instead??

Postby rellison » Sat Mar 09, 2013 5:48 am

OK Here is what I have done but this does not seem to work for me for some reason.

I found a function that will extract between a start point and an end point.

Code: Select all
function extractString($start,$end,$total){
$total = stristr($total,$start);
$f2 = stristr($total,$end);
return substr($total,strlen($start),-strlen($f2));
}


and I am calling the function like this:
Code: Select all
$temp=extractString("<OPERATOR:","<",$string);
   echo($temp);
   $arr=split(">",$temp);
   $garbage=$arr[0];
   $qso_data['MyCallsign']=$arr[1];


If I set an echo at the top of the function everything is getting to the top of it. But does anyone see why it would not return anything back to the calling routine??

TIA
Rick
rellison
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Aug 03, 2011 3:00 pm

Re: What can I do instead??

Postby johnj » Sun Mar 10, 2013 6:30 am

store substr($total,strlen($start),-strlen($f2)); to a variable and echo it. Then you will know why that function is not returning anything.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.