jaacmmason Posted May 2, 2013 Share Posted May 2, 2013 I have this very basic code to remove the javascript function call window.open from display pages on our Intranet site. Since eregi has become depreciated, I have tried to get other code to work. The code is: if($fp) { while(($line = fgets($fp)) !== false) { if (!eregi("window.open",$line)) { print $line; } } } I have changed it to: if($fp) { while(($line = fgets($fp)) !== false) { if (!stristr("window.open",$line)) { print $line; } } } However the window.open is still being called and opening up a 2nd page of data. Is there something I am missing in reference to the stristr call? Quote Link to comment https://forums.phpfreaks.com/topic/277552-need-help-changing-depreciated-eregi-code/ Share on other sites More sharing options...
Christian F. Posted May 2, 2013 Share Posted May 2, 2013 As you've correctly determined, you don't need to use a regular expression for this. However, try with using this instead of the stristr call: if (strpos ($line, "window.open") !== false)) { Quote Link to comment https://forums.phpfreaks.com/topic/277552-need-help-changing-depreciated-eregi-code/#findComment-1427790 Share on other sites More sharing options...
.josh Posted May 17, 2013 Share Posted May 17, 2013 but for the sake of answering the original question, we have a sticky in this forum addressing this. Good practice, looking at stickies before posting. ereg and "deprecated" error Quote Link to comment https://forums.phpfreaks.com/topic/277552-need-help-changing-depreciated-eregi-code/#findComment-1430584 Share on other sites More sharing options...
dalecosp Posted May 17, 2013 Share Posted May 17, 2013 (edited) Why not just do it with Javascript? <script type='text/javascript'> window.open = function() { return; } </script>A dysfunctional function! Edited May 17, 2013 by dalecosp Quote Link to comment https://forums.phpfreaks.com/topic/277552-need-help-changing-depreciated-eregi-code/#findComment-1430661 Share on other sites More sharing options...
joea Posted June 6, 2013 Share Posted June 6, 2013 if (preg_match('/window\.open/',$line)) will do this job for single line text if (preg_match('/window\.open/s',$line)) if there any line breakes in $line Quote Link to comment https://forums.phpfreaks.com/topic/277552-need-help-changing-depreciated-eregi-code/#findComment-1434518 Share on other sites More sharing options...
Christian F. Posted June 6, 2013 Share Posted June 6, 2013 The only thing the "s" modifier does is make the dot (.) match newlines as well. Since there are no (matching) dots in the Regular Expression, as the only one there is escaped, that modifier won't do anything. Quote Link to comment https://forums.phpfreaks.com/topic/277552-need-help-changing-depreciated-eregi-code/#findComment-1434572 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.