我使用PHP Simple HTML DOM Parser,我想向HTML DOM添加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);
请使用strpos()和substr()查找位置,然后添加。