newbtophp Posted September 26, 2009 Share Posted September 26, 2009 I have text which is like: <script LANGUAGE="JavaScript"><!-- document.write(unescape("%3C%53%43%52%49%50%54%20%4C%41%4E%47%55%41%47%45%3D%22%4A%61%"));//--></SCRIPT> Im trying to get all the contents after that code. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/175641-solved-simple-preg_match-help/ Share on other sites More sharing options...
MadTechie Posted September 26, 2009 Share Posted September 26, 2009 try this <?php $html = '<script LANGUAGE="JavaScript"><!-- document.write(unescape("%3C%53%43%52%49%50%54%20%4C%41%4E%47%55%41%47%45%3D%22%4A%61%"));//--></SCRIPT>'; if (preg_match('/unescape\((["\'])([\da-f%]*?)\1\)/i', $html, $regs)) { echo urldecode($regs[2]); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/175641-solved-simple-preg_match-help/#findComment-925524 Share on other sites More sharing options...
newbtophp Posted September 26, 2009 Author Share Posted September 26, 2009 I think i've confused you, Im trying to echo all code found after the end </SCRIPT> tag. Quote Link to comment https://forums.phpfreaks.com/topic/175641-solved-simple-preg_match-help/#findComment-925551 Share on other sites More sharing options...
MadTechie Posted September 26, 2009 Share Posted September 26, 2009 that's not what you asked and from the first question you haven't given any details i can work with! Quote Link to comment https://forums.phpfreaks.com/topic/175641-solved-simple-preg_match-help/#findComment-925557 Share on other sites More sharing options...
newbtophp Posted September 26, 2009 Author Share Posted September 26, 2009 that's not what you asked and from the first question you haven't given any details i can work with! Sorry i was tired, for example: I have this code: $file = file_get contents($upload); echo $file; Its an upload form where i echo whats directally uploaded, the uploaded file always contains urlencoded data which is wrapped in script tags, but the trouble is i want to only echo the code after the first </SCRIPT> end tag. So lets say i have uploaded: <script LANGUAGE="JavaScript"><!-- document.write(unescape("%3C%53%43%52%49%50%54%20%4C%41%4E%47%55%41%47%45%3D%22%4A%61%"));//--></SCRIPT> <SCRIPT> text etc. </script> <script LANGUAGE="JavaScript"> more js... </script> <html> It will only echo: <SCRIPT> text etc. </script> <script LANGUAGE="JavaScript"> more js... </script> <html> I thought it can possibly be done by preg_match but not intially sure Quote Link to comment https://forums.phpfreaks.com/topic/175641-solved-simple-preg_match-help/#findComment-925561 Share on other sites More sharing options...
Garethp Posted September 26, 2009 Share Posted September 26, 2009 $file = preg_replace('~<script.*?</script>~i', '', $file, 1); or preg_match('~^.*?</script>(.+)$~i', $file, $M); Quote Link to comment https://forums.phpfreaks.com/topic/175641-solved-simple-preg_match-help/#findComment-925564 Share on other sites More sharing options...
MadTechie Posted September 26, 2009 Share Posted September 26, 2009 I would go with $html = preg_replace('%^.*?</script>%si', '', $html); Quote Link to comment https://forums.phpfreaks.com/topic/175641-solved-simple-preg_match-help/#findComment-925572 Share on other sites More sharing options...
newbtophp Posted September 27, 2009 Author Share Posted September 27, 2009 Thanks MadTechie and garethp! Quote Link to comment https://forums.phpfreaks.com/topic/175641-solved-simple-preg_match-help/#findComment-925871 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.