LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-17-2011, 04:37 PM   #1
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
php: how to parse data into variables?


My php knowledge is very poor (only worked with strings so far), and I am faced which a task that is a real challenge for me:
I have a variable, that contains data of different type, in this order:
byte, byte, string, string, string, string, short, byte, byte, byte, byte, byte, byte, byte, string

Strings are of variable length. How could this data be parsed into variables of the right type, and then all converted to strings?
What are the functions to use?

P.S.
Strings are unicode ones, and they are delimited by "

Last edited by J_Szucs; 04-17-2011 at 05:14 PM.
 
Old 04-17-2011, 05:54 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
We wouldn't know unless you posted some actual data?

No idea where your data is coming from, or how that motley bunch
got assigned to a single variable - can't really answer your
question(s) at all.


Cheers,
Tink
 
Old 04-17-2011, 07:19 PM   #3
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
Thank you, but I have almost solved this (after realizing that most php string function are "byte safe"), I only need a little help now:

Strings seem to be separated not by " but by ascii 0 characters (at least ord returned 0 as the ascii code of the character following each string in the data).

Why does this return nothing then?:
/ $string contains the data
$delim = "%00";
$pos = strpos ($string, $delim);
echo $pos;

The only thing I need to solve this is to get the position of the ascii 0 character, but the above prints nothing, $pos seem to be empty...

Last edited by J_Szucs; 04-17-2011 at 07:26 PM.
 
Old 04-17-2011, 07:23 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Try "\0" instead of "%00".
 
Old 04-17-2011, 07:33 PM   #5
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
That's it, thank you!

I would have never figured that out, as I have a working sample code in which the "%00" syntax worked like a charm in the str_replace function...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script: parse active process stderr, strip, dump into variables, use variables TimeFade Programming 1 02-13-2010 06:09 AM
PHP Error Parse error: parse error, unexpected $ in /home/content/S/k/i/SkinCare4U/h CowanServices Programming 2 12-09-2008 08:26 PM
PHP: storing all data form a db row in variables with the same name as the db column konqi Programming 2 07-10-2008 05:13 AM
Help w/ script to read file and parse variables cslink23 Linux - General 18 11-26-2006 02:22 AM
Problems with php 4.2.1 form-data and hidden variables coea77 Programming 1 10-10-2002 03:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration