0

I have a variable in my PHP code where its equal to a stored string. A small portion of this string is taken and used as a preview on a different page. On occasion there will be Javascript in that string, how could I say the following:

Pseudocode:
if stringVar contains "<script"
then remove the substring starting at "<script" and ending at "/script>"
VikingGoat
  • 387
  • 3
  • 8
  • 30
  • Are you sure that within that text, you will _NEVER_ find another instance of " – Nightfirecat Nov 08 '11 at 01:05
  • Are you by chance looking for [`strip_tags`](http://php.net/strip_tags)? – deceze Nov 08 '11 at 01:15

2 Answers2

1

If you're just getting rid of script tags:

$result = preg_replace('%<script>.*</script>%i', '', $subject);
nickb
  • 59,313
  • 13
  • 108
  • 143
0

strpos function returns the position of one string in another,

so your start is strpos($SomeString,"<script")

end is strpos($SomeString,"/script>") + 7 

after that it's just substr to get everything before and after.

Note this will not work if <script can contains the <Script /Script> tags...
Tony Hopkinson
  • 20,172
  • 3
  • 31
  • 39