Jump to content

Parse this string


Recommended Posts

Hi.

How would you parse the string bellow? Which format is it?

Thank you for help.

a:13:{i:0;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:1;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:2;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:7:{i:0;s:1:"1";i:1;s:1:"1";i:2;s:1:"1";i:3;s:1:"1";i:4;s:1:"1";i:5;s:1:"1";i:6;s:1:"1";}s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:3;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:4;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:5;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:6;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:1:{i:2;s:1:"1";}s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"12:35";s:3:"end";s:0:"";}i:7;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"12:25";s:3:"end";s:10:"08.06.2019";}i:8;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:9;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:10:{i:0;s:1:"1";i:1;s:1:"1";i:2;s:1:"1";i:3;s:1:"1";i:4;s:1:"1";i:5;s:1:"1";i:6;s:1:"1";i:7;s:1:"1";i:8;s:1:"1";i:9;s:1:"1";}s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:10;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:11;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:13;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"13:34";s:3:"end";s:0:"";}}

 

Link to comment
Share on other sites

  • Moderators

@TiRep welcome to the forum. You unfortunately could not have provided less information if you'd been actively trying. How about telling us where the string originates from (application, website, etc.), what it represents, how you are trying to parse it, etc. etc. Help us help you.

Also, please see the link in my signature about how to ask smart questions on the forum.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

it is parsed, and it looks like JSON but JSON looks like a lot of other stuff.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Local $sData = 'a:13:{i:0;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:1;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:2;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:7:{i:0;s:1:"1";i:1;s:1:"1";i:2;s:1:"1";i:3;s:1:"1";i:4;s:1:"1";i:5;s:1:"1";i:6;s:1:"1";}s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:3;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:4;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:5;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:6;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:1:{i:2;s:1:"1";}s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"12:35";s:3:"end";s:0:"";}i:7;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"12:25";s:3:"end";s:10:"08.06.2019";}i:8;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:9;a:5:{s:7:"section";s:1:"1";s:6:"levels";a:10:{i:0;s:1:"1";i:1;s:1:"1";i:2;s:1:"1";i:3;s:1:"1";i:4;s:1:"1";i:5;s:1:"1";i:6;s:1:"1";i:7;s:1:"1";i:8;s:1:"1";i:9;s:1:"1";}s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:10;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:11;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"07.06.2019";s:4:"time";s:5:"15:15";s:3:"end";s:0:"";}i:13;a:4:{s:7:"section";s:1:"1";s:4:"date";s:10:"05.06.2019";s:4:"time";s:5:"13:34";s:3:"end";s:0:"";'

Parse($sData)

Func Parse($sData)
    Local $rx = StringRegExp($sData,'(a:\d+:\{)|(s:\d+:"[^"]*";)(a:\d+:\{)|(s:\d+:"[^"]*";s:\d+:"[^"]*";)|(i:\d+;)|(\})',3), $vsOut[1][2] = [[0]], $iTabs = 0, $sTabs
    For $d In $rx
        If $d Then
            $sTabs = _repeat(@TAB, $iTabs)
            Select
                Case StringRegExp($d, 's:\d+:"([^"]+)";s:\d+:"([^"]*)";', 0)
                    $r = StringRegExp($d, 's:\d+:"([^"]+)";s:\d+:"([^"]*)";', 3)
                    _addToArray($vsOut, $sTabs, $r[0] & " = ", $r[1])

                Case StringRegExp($d, 's:\d+:"([^"]+)";', 0)
                    _addToArray($vsOut, $sTabs, StringRegExpReplace($d, '(s:\d+:")([^"]+)(");', '$2'), '')

                Case StringRegExp($d, 'i:\d+;', 0)
                    _addToArray($vsOut, $sTabs, 'Element' & " # ", StringRegExpReplace($d, '(i:)(\d+)(;)', '$2'))

                Case StringRegExp($d, 'a:\d+:\{', 0)
                    _addToArray($vsOut, $sTabs, 'Array[', StringRegExpReplace($d, '(a:)(\d+)(:\{)', '$2') & '] = {')
                    $iTabs += 1

                Case $d = '}'
                    _addToArray($vsOut, $sTabs, '}', '')
                    $iTabs -= 1

                Case Else
                    If $d Then ConsoleWrite('The following data was unhandeled [' & $d & ']' & @CRLF)
            EndSelect
        EndIf
    Next
    For $i = 1 To $vsOut[0][0]
        ConsoleWrite($vsOut[$i][0] & $vsOut[$i][1] & @CRLF)
    Next
EndFunc
Func _addToArray(ByRef $a, $sTabs, $ele0, $ele1)
    $a[0][0] += 1
    ReDim $a[$a[0][0] + 1][2]
    $a[$a[0][0]][0] = $sTabs & $ele0
    $a[$a[0][0]][1] = $ele1
EndFunc
Func _repeat($sStr, $i)
    Local $sRet = ''
    For $n = 1 To $i
        $sRet &= $sStr
    Next
    Return $sRet
EndFunc

I was bored so i wrote a little script to parse the data, it does a fair job of it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...