简体   繁体   中英

How to get javascript variable value from html dump/content?

From an html content like below, I am trying to get with a php script the content of the javascript array variable "aDataSet". I believe I could use a regular expression but so far I haven't been able to export the data.

What would be the best way to do that? The html content is loaded in a php variable. Ideally I would like to get the information in a php array?

Any idea?

Thank you

<html>
    <head>
    </head>
    <body>
        <!-- html code -->
        <script type="text/javascript">
            var imgShowBtn = '<img src="templates/medias/search.png" title="See form" />';
            var imgEditBtn = '<img src="templates/medias/update.png" title="Modify the complaint" />';
            var imgPdfBtn = '<img src="templates/medias/pdf.jpg" title="See report" />';

            jQuery.fn.dataTableExt.oSort['date-case-asc'] = TriDateFrAsc;
            jQuery.fn.dataTableExt.oSort['date-case-desc'] = TriDateFrDesc;

            var aDataSet = [
            ["   ","1202 26a", "02/29/2012", "01/17/2012", "akdslj91", "345910K30", "Berlin 800905", "4" ],
            ["   ","1202 152", "02/29/2012", "01/17/2012", "ahkqos12", "134711223", "qwerty 5493", "4" ],
            ["   ","1202 241", "02/29/2012", "01/13/2012", "ahkqos12", "345910130", "azerty 1020090951", "4" ],
            ["   ","1202 222", "02/29/2012", "01/31/2012", "askj192a", "136411208", "paris 1020090520", "4" ] ];
        </script>
        <!-- html code -->
    </body>
</html>

Your use case is not wholly detailed but maybe you could also use the PHPs json_decode function which takes and string representing a Javscript object:

Example

<?php
$strDataset = '[ [" ","1202 26a", "02/29/2012", "01/17/2012", "akdslj91", "345910K30", "Berlin 800905", "4" ], [" ","1202 152", "02/29/2012", "01/17/2012", "ahkqos12", "134711223", "qwerty 5493", "4" ], [" ","1202 241", "02/29/2012", "01/13/2012", "ahkqos12", "345910130", "azerty 1020090951", "4" ], [" ","1202 222", "02/29/2012", "01/31/2012", "askj192a", "136411208", "paris 1020090520", "4" ] ]';
var_dump(json_decode($strDataset));

Code with output available at http://ideone.com/ehzZIY

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM