1

I have made a regular expression to remove a script tag from a imported page.(used curl) <script[\s\S]*?/script> this is my expresion

when i used it with preg_replace to remove the tag it gave me this error

Warning: preg_replace() [function.preg-replace]: Unknown modifier 'c' in C:\xampp\htdocs\get_page.php on line 21

can anyone help me

thanks

1
  • Clearly that isn't the entire line that you have posted. Please post enough so that we can clearly see what you are actually doing. Commented Mar 16, 2012 at 20:11

5 Answers 5

2

You should choose a suitable delimiter for your regular expression (preferably one that doesn't' occur anywhere in your pattern, so that you don't need to escape). For example:

"#<script[\s\S]*?/script>#"

Also, don't do that if you are trying to prevent malicious people from injecting Javascript into your page. It can easily be worked around. Use a whitelist of known safe constructs rather than trying to remove dangerous code.

Sign up to request clarification or add additional context in comments.

Comments

1

PHP requires delimiters on RegExp patterns. Also, your expression can be simplified.

|<script.+/script>|

Comments

0

Did you wrap your regexp in forward slashes?

$str = preg_replace('/<script[\s\S]*?\/script>/', ...);

Comments

0

Did you surround your regular expression with a delimiter, such as /? If you didn't, you need to. If you did, and you used / (as opposed to your other choices) you'll need to escape the / in your /script, so it'll look like \/script instead.

Comments

0

Use the following code :

$result = preg_replace('%<script[\s\S]*?/script>%', $change_to, $subject);

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.