Jump to content

preg_match javascript


Pro.Luv

Recommended Posts

Hi,

 

Im still getting used to regex and I need some help could someone show

me how to match javascript like :

 

 

<script type="text/javascript">

function one(){
  code....
}

</script>

 

 

how can I match this in html code ?  I'm reading a file into a string I want to then find if theres

javascript in the code and remove it ?

 

Im using this to read the file:

$html =  file_get_contents("test.html");

 

Please help !

 

 

 

Link to comment
Share on other sites

<?php
$string = "test <script >
function () {

}

</script> other text

text of more.
<script type=\"text/javascript\">
var test=1;
function test() {

}test
</script>

more text ok";

echo preg_replace('~<script(.+?)</script>~si', " ", $string);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.