Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP简单HTML DOM解析器:我想用PHP简单DOM解析器向HTML DOM添加javascript链接_Php_Html_Dom - Fatal编程技术网

PHP简单HTML DOM解析器:我想用PHP简单DOM解析器向HTML DOM添加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

我使用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, '</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()查找位置,然后添加