使用PHP访问DOM的脚本元素

时间:2015-09-16 19:40:17

标签: javascript html dom

我必须使用PHP访问DOM元素中的以下mp3文件名。我使用getElementsByTagName获取了所有脚本元素,但无法获取文件名。

 <script type="text/javascript">
    //<![CDATA[
    $(document).ready(function () {
        $("#jquery_jplayer_1").jPlayer({
            ready: function () {
                $(this).jPlayer("setMedia", {
                    mp3: 'http://d2ik8svv2swg1p.cloudfront.net/courses/39T.mp3'
                });
            },
            ended: function (event) {
                $("#jquery_jplayer_1").jPlayer("play", 0);
            },
            swfPath: "/js",
            supplied: "mp3",
            cssSelectorAncestor: "#jp_interface_1"
        })
.bind($.jPlayer.event.play, function () { 
    $(this).jPlayer("pauseOthers");
});

1 个答案:

答案 0 :(得分:-1)

这会变得丑陋......

<?php
    error_reporting(E_ALL);
header("content-type: text/plain;charset=utf8");
$html=base64_decode('IDxzY3JpcHQgdHlwZT0idGV4dC9qYXZhc2NyaXB0Ij4NCiAgICAvLzwhW0NEQVRBWw0KICAgICQoZG9jdW1lbnQpLnJlYWR5KGZ1bmN0aW9uICgpIHsNCiAgICAgICAgJCgiI2pxdWVyeV9qcGxheWVyXzEiKS5qUGxheWVyKHsNCiAgICAgICAgICAgIHJlYWR5OiBmdW5jdGlvbiAoKSB7DQogICAgICAgICAgICAgICAgJCh0aGlzKS5qUGxheWVyKCJzZXRNZWRpYSIsIHsNCiAgICAgICAgICAgICAgICAgICAgbXAzOiAnaHR0cDovL2QyaWs4c3Z2MnN3ZzFwLmNsb3VkZnJvbnQubmV0L2NvdXJzZXMvMzlULm1wMycNCiAgICAgICAgICAgICAgICB9KTsNCiAgICAgICAgICAgIH0sDQogICAgICAgICAgICBlbmRlZDogZnVuY3Rpb24gKGV2ZW50KSB7DQogICAgICAgICAgICAgICAgJCgiI2pxdWVyeV9qcGxheWVyXzEiKS5qUGxheWVyKCJwbGF5IiwgMCk7DQogICAgICAgICAgICB9LA0KICAgICAgICAgICAgc3dmUGF0aDogIi9qcyIsDQogICAgICAgICAgICBzdXBwbGllZDogIm1wMyIsDQogICAgICAgICAgICBjc3NTZWxlY3RvckFuY2VzdG9yOiAiI2pwX2ludGVyZmFjZV8xIg0KICAgICAgICB9KQ0KLmJpbmQoJC5qUGxheWVyLmV2ZW50LnBsYXksIGZ1bmN0aW9uICgpIHsgDQogICAgJCh0aGlzKS5qUGxheWVyKCJwYXVzZU90aGVycyIpOw0KfSk7DQo=');

$domd=@DOMDocument::loadHTML($html);
$ele=$domd->getElementsByTagName("script");
$ele=$ele[0];
$matches=array();
$i=preg_match_all('/mp3\s*\:[^\\\']*\\\'([^\\\']*)/i',$ele->textContent,$matches);
$url=$matches[1][0];
$name=basename($url);
var_dump($name,$url,$matches,$i);

您的姓名现在是$ name