PHP简单HTML DOM解析器:我想用PHP简单DOM解析器向HTML DOM添加javascript链接
我使用PHP简单HTMLDOM解析器,我想向HTMLDOM添加javascript链接。 这是我的密码PHP简单HTML DOM解析器:我想用PHP简单DOM解析器向HTML DOM添加javascript链接,php,html,dom,Php,Html,Dom,我使用PHP简单HTMLDOM解析器,我想向HTMLDOM添加javascript链接。 这是我的密码 $html= file_get_contents("http://example.com") 我想补充一点 <script type="text/javascript" src="http://exapmle.com/example.js"></script> 链接到头标签之间。 有谁知道解决方案吗?试试这个: $head_pos = strpos($html
$html= file_get_contents("http://example.com")
我想补充一点
<script type="text/javascript" src="http://exapmle.com/example.js"></script>
链接到头标签之间。
有谁知道解决方案吗?试试这个:
$head_pos = strpos($html, '</head>'); // find position of the </head>
$newHtml = substr($html, 0, $head_pos) . $stringToAdd . substr($html, $head_pos);
$head\u pos=strpos($html,);//查找
$newHtml=substr($html,0,$head\u pos)$stringToAdd。substr($html,$head\u pos);
试试这个:
$head_pos = strpos($html, '</head>'); // find position of the </head>
$newHtml = substr($html, 0, $head_pos) . $stringToAdd . substr($html, $head_pos);
$head\u pos=strpos($html,);//查找
$newHtml=substr($html,0,$head\u pos)$stringToAdd。substr($html,$head\u pos);
请使用strps()和substr()查找位置,然后添加。请使用strps()和substr()查找位置,然后添加