1

I have a parsed html data fetched with @file_get_contents($url) which is like

<script type="text/javascript">var stock = 
new Array();
stock['704'] = new Array('92 (1-2)', 913, 'n.A.', '104 (3-4)', 2371, 'n.A.', '116 (5-6)', 1921, 'n.A.', '128 (7-8)', 4626, 'n.A.', '140 (9-10)', 4222, 'n.A.', '152 (11-12)', 4281, 'n.A.');
stock['101'] = new Array('92 (1-2)', 3444, 'n.A.', '104 (3-4)', 10136, 'n.A.', '116 (5-6)', 18834, 'n.A.', '128 (7-8)', 30662, 'n.A.', '140 (9-10)', 28981, 'n.A.', '152 (11-12)', 25982, 'n.A.');
stock['540'] = new Array('92 (1-2)', 505, 'n.A.', '104 (3-4)', 1220, 'n.A.', '116 (5-6)', 1634, 'n.A.', '128 (7-8)', 1381, 'n.A.', '140 (9-10)', 3187, 'n.A.', '152 (11-12)', 5014, 'n.A.');
stock['700'] = new Array('92 (1-2)', 401, 'n.A.', '104 (3-4)', 724, 'n.A.', '116 (5-6)', 1078, 'n.A.', '128 (7-8)', 1247, 'n.A.', '140 (9-10)', 2767, 'n.A.', '152 (11-12)', 2207, 'n.A.');
stock['448'] = new Array('92 (1-2)', 517, 'n.A.', '104 (3-4)', 727, 'n.A.', '116 (5-6)', 1721, 'n.A.', '128 (7-8)', 1537, 'n.A.', '140 (9-10)', 2382, 'n.A.', '152 (11-12)', 1820, 'n.A.');
stock['423'] = new Array('92 (1-2)', 876, 'n.A.', '104 (3-4)', 1110, 'n.A.', '116 (5-6)', 5196, 'n.A.', '128 (7-8)', 3159, 'n.A.', '140 (9-10)', 7727, 'n.A.', '152 (11-12)', 3656, 'n.A.');
stock['121'] = new Array('92 (1-2)', 781, 'n.A.', '104 (3-4)', 13363, 'n.A.', '116 (5-6)', 13300, 'n.A.', '128 (7-8)', 1964, 'n.A.', '140 (9-10)', 3591, 'n.A.', '152 (11-12)', 2552, 'n.A.');
stock['719'] = new Array('92 (1-2)', 188, 'n.A.', '104 (3-4)', 1313, 'n.A.', '116 (5-6)', 2109, 'n.A.', '128 (7-8)', 2076, 'n.A.', '140 (9-10)', 2292, 'n.A.', '152 (11-12)', 2674, 'n.A.');    var imageTmp = new Array();
</script><body>

final output which i require is MultiDimensional Array which needs to be like this. The values like 92 (1-2) could be alphabets as well.

Array
(
    [704] => Array
        (
            [92 (1-2)] => Array
        (
            [qty] => 913
            [price] => n.A

        )
            [104 (3-4)] => Array
        (
            [qty] => 2371
            [price] => n.A

        )
            [116 (5-6)] => Array
        (
            [qty] => 1921
            [price] => n.A

        )       
        )

    [101] => Array
        (
            [92 (1-2)] => Array
        (
            [qty] => 3444
            [price] => n.A

        )
            [104 (3-4)] => Array
        (
            [qty] => 10136
            [price] => n.A

        )
            [116 (5-6)] => Array
        (
            [qty] => 18834
            [price] => n.A

        )       
        )

    [700] => Array
        (
            [XS] => Array
        (
            [qty] => 3444
            [price] => n.A

        )
            [L] => Array
        (
            [qty] => 10136
            [price] => n.A

        )
            [S] => Array
        (
            [qty] => 18834
            [price] => n.A

        )       
        )

)

how could i get this

3
  • @alvin-brown welcome! Alvin you must be more specific in your question.... Commented Nov 17, 2011 at 10:36
  • Do you have influence on "the source"? I.e. can you change the script on the other server that provides the data? Commented Nov 17, 2011 at 11:38
  • I dont have any control on other server. the input string is parsed from html. Commented Nov 17, 2011 at 11:50

1 Answer 1

1

You probably print an array on a page, and you then fetch the contents of that page using file_get_contents. Your problem is that the content is not an array?

A quick solution to this is that you output the array as an serialized string. You can then simply do unserialize to have a workable array again.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.