3

i need to find inline javascript with php regex. I can find external script, but not inline, can anybody help me?

Here is my pattern for external:

"/<script(.*?)src(.*?)>(.*?)<\/script\s*>/smi"

Any ideas?

Felix Kling
  • 756,363
  • 169
  • 1,062
  • 1,111
Simon
  • 43
  • 1
  • 4

3 Answers3

4
"/<script((?:(?!src=).)*?)>(.*?)<\/script>/smix"

(My first look-ahead regex ;))

Please note that you should not parse HTML with regexes, see:

https://stackoverflow.com/a/1732454/221213

KARASZI István
  • 29,989
  • 8
  • 97
  • 120
  • Yes, this is for all scripts, but I need the one, without src attribute in opening tag – Simon Sep 24 '10 at 15:30
  • cool this almost is correct :) You just need to add ? after first * : "/ – Simon Sep 24 '10 at 17:49
2

You need to find all those cases where inline script can be used (i.e. all listener functions onClick, onBlur, onMouseDown, onMouseUp, on...)).

Thariama
  • 49,060
  • 11
  • 131
  • 155
  • No, i haev HTML doc ant i need to find text like but not – Simon Sep 24 '10 at 15:26
  • 1
    @no, there are enough ways to run JS. Another way: ``. A better solution would be whitelisting using an application like HTML Purifier. – Lekensteyn Sep 24 '10 at 15:28
0
"/<script[^\>]*>(.?)<\/script>/si"
Vadim
  • 4,964
  • 2
  • 19
  • 18