【问题标题】:PHP Simple HTML DOM Parser: I want to add javascript link to html dom with php simple dom parserPHP Simple HTML DOM Parser: 我想用 php simple dom parser 将 javascript 链接添加到 html dom
【发布时间】:2015-12-31 16:29:47
【问题描述】:

我使用 PHP Simple HTML DOM Parser,我想将 javascript 链接添加到 html dom。 这是我的代码。

$html=  file_get_contents("http://example.com")

我要添加

<script type="text/javascript" src="http://exapmle.com/example.js"></script>

head 标签之间的链接。 谁知道解决办法?

【问题讨论】:

    标签: php html dom


    【解决方案1】:

    试试这个:

    $head_pos = strpos($html, '</head>'); // find position of the </head>
    $newHtml = substr($html, 0, $head_pos) . $stringToAdd . substr($html, $head_pos);
    

    【讨论】:

      【解决方案2】:

      请使用 strpos() 和 substr() 查找位置然后添加。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-04
        • 1970-01-01
        • 1970-01-01
        • 2011-09-04
        • 1970-01-01
        • 2019-09-21
        • 2016-04-09
        相关资源
        最近更新 更多