1

I use PHP Simple HTML DOM Parser and I want to add javascript link to html dom. Here is my code.

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

I want to add

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

link to between head tag. Anyone who knows solution?

2 Answers 2

2

Try this:

$head_pos = strpos($html, '</head>'); // find position of the </head>
$newHtml = substr($html, 0, $head_pos) . $stringToAdd . substr($html, $head_pos);
Sign up to request clarification or add additional context in comments.

Comments

2

Please use strpos() and substr() to find position and then add.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.