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? 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)) { 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 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 Why not just do it with Javascript? <script type='text/javascript'> window.open = function() { return; } </script>A dysfunctional function! 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 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. 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
Archived
This topic is now archived and is closed to further replies.