I have a 3rd party script in which I have no control over the HTML and can only modify the basic CSS. I just wanted to know if it is possible to cut all the information from < script> until its closing </ script> without distinguishing between the elements inside?
Example :
<script src='http://localhost:8888/Sadem/wordpress/wp-content/plugins/elementor/assets/js/frontend.min.js?ver=3.5.3'
id='elementor-frontend-js'></script>
So for example here I would like to retrieve the whole line in string form to store it in an array.
$document = new DOMDocument();
libxml_use_internal_errors(true);
$document->loadHTML($content);
libxml_use_internal_errors(false);
// An empty array to store all the 'srcs'
$scripts_array = [];
// Store every script's source inside the array
foreach ($document->getElementsByTagName('script') as $script) {
if ($script->hasAttribute('src')) {
$scripts_array[] = $script->getAttribute('src');
}
}
So here is a piece of my code, for now I manage to retrieve the loaded document, browse the scripts but I only pull the “src” attribute; but I want to retrieve all the content without distinction.
Thank you for your answers ! 🙂