如何从html dump/content中获取javascript变量值

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

本文关键字:获取 javascript 变量值 content html dump      更新时间:2023-09-26

从下面这样的html内容中,我试图用php脚本获取javascript数组变量"aDataSet"的内容。我相信我可以使用正则表达式,但到目前为止我还无法导出数据。

最好的方法是什么?html内容加载在php变量中。理想情况下,我想在php数组中获取信息?

知道吗?

谢谢

<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>

您的用例并不完全详细,但也许您也可以使用PHPs json_decode函数,该函数接受表示Javscript对象的字符串:

示例

<?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));

输出可用的代码http://ideone.com/ehzZIY