Re: What's wrong with this code?

From: Date: Mon, 21 May 2001 14:23:12 +0000
Subject: Re: What's wrong with this code?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-53722@lists.php.net to get a copy of this message
Since there is a "/" in the code itself, I use "#" as a delimiter instead so I don't have to escape it, making it harder to read. So here's the code: $file = preg_replace("#<script.*>.*</script>#Ui", "<!-- RWW: Scripting killed -->", $file); Which works...kinda. But here's the weird thing. This is a piece of code in the HTML which will be replaced: <SCRIPT Language='JavaScript'> <!-- function changeimage(imgNam,status) { if (document.images) { document[imgNam].src=eval(imgNam + '_' + status + '.src'); } } // --> </SCRIPT> <SCRIPT LANGUAGE='JavaScript'> <!-- if (document.images) { // Preload images for onclick image change function major1_on = new Image(); major1_on.src = '/nav/1-on.gif'; major1_off = new Image(); major1_off.src = '/nav/1-off.gif'; major1_over = new Image(); major1_over.src = '/nav/1-over.gif'; } // --> </SCRIPT> And here's the weird part. When I run my preg code on just that piece of code, it does absolutely nothing to it. This is the whole code I'm using to test: <?php $file = "<SCRIPT Language='JavaScript'> <!-- function changeimage(imgNam,status) { if (document.images) { document[imgNam].src=eval(imgNam + '_' + status + '.src'); } } // --> </SCRIPT> <SCRIPT LANGUAGE='JavaScript'> <!-- if (document.images) { // Preload images for onclick image change function major1_on = new Image(); major1_on.src = '/nav/1-on.gif'; major1_off = new Image(); major1_off.src = '/nav/1-off.gif'; major1_over = new Image(); major1_over.src = '/nav/1-over.gif'; major2_on = new Image(); major2_on.src = '/nav/2-on.gif'; major2_off = new Image(); major2_off.src = '/nav/2-off.gif'; major2_over = new Image(); major2_over.src = '/nav/2-over.gif'; major3_on = new Image(); major3_on.src = '/nav/3-on.gif'; major3_off = new Image(); major3_off.src = '/nav/3-off.gif'; major3_over = new Image(); major3_over.src = '/nav/3-over.gif'; major4_on = new Image(); major4_on.src = '/nav/4-on.gif'; major4_off = new Image(); major4_off.src = '/nav/4-off.gif'; major4_over = new Image(); major4_over.src = '/nav/4-over.gif'; major5_on = new Image(); major5_on.src = '/nav/5-on.gif'; major5_off = new Image(); major5_off.src = '/nav/5-off.gif'; major5_over = new Image(); major5_over.src = '/nav/5-over.gif'; major6_on = new Image(); major6_on.src = '/nav/6-on.gif'; major6_off = new Image(); major6_off.src = '/nav/6-off.gif'; major6_over = new Image(); major6_over.src = '/nav/6-over.gif'; major7_on = new Image(); major7_on.src = '/nav/7-on.gif'; major7_off = new Image(); major7_off.src = '/nav/7-off.gif'; major7_over = new Image(); major7_over.src = '/nav/7-over.gif'; major8_on = new Image(); major8_on.src = '/nav/8-on.gif'; major8_off = new Image(); major8_off.src = '/nav/8-off.gif'; major8_over = new Image(); major8_over.src = '/nav/8-over.gif'; major28_on = new Image(); major28_on.src = '/nav/28-on.gif'; major28_off = new Image(); major28_off.src = '/nav/28-off.gif'; major28_over = new Image(); major28_over.src = '/nav/28-over.gif'; major29_on = new Image(); major29_on.src = '/nav/29-on.gif'; major29_off = new Image(); major29_off.src = '/nav/29-off.gif'; major29_over = new Image(); major29_over.src = '/nav/29-over.gif'; } // --> </SCRIPT>"; $file = preg_replace("#<script.*>.*?</script>#i", "<!-- RWW: Scripting killed -->", $file); echo $file; ?> Does nothin. Haven't the foggiest clue as to why, but here's what's really making me sick. By running it on http://www.theregister.co.uk which is where I got the code I'm trying to strip down, this is what I do in my code: <?php $target = 'http://www.theregister.co.uk'; $fp = fopen($target, "r"); $file = fread($fp, 10000000); // kill scripting $file = preg_replace("#<script.*>.*?</script>#i", "<!-- RWW: Scripting killed -->", $file); echo $file; ?> When run it misses the first use of SCRIPT that I posted above, but it catches the second one! And I don't know why! ;( Plutarck "Rasmus Lerdorf" <rasmus@php.net> wrote in message news:Pine.LNX.4.33.0105210625130.990-100000@rasmus.php.net... > > But I use PCRE functions, so I don't want to use ereg in one place and PCRE > > in another, so I tried: > > > > $file = preg_replace("#<script.*>.*</script>#i", "<!-- RWW: > > Scripting > > killed -->", $file); > > '/<script.*>.*?<\/script>/i' > > -Rasmus > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#53722) next »