firedealer Posted May 10, 2011 Share Posted May 10, 2011 I know $regex_pattern is wrong but I need a solution to find a content between <body> and </body>. <?php $content = "<html><head><title>Your IP</title></head><body>Your IP Address: 63.1.142.154</body></html>"; $regex_pattern = "/<body>(.*)<\/body>/"; $preg_match($regex_pattern,htmlspecialchars($content),$matches); print_r( $matches ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235971-preg_match/ Share on other sites More sharing options...
firedealer Posted May 10, 2011 Author Share Posted May 10, 2011 Oops! I'm suppose to post in regex section. Quote Link to comment https://forums.phpfreaks.com/topic/235971-preg_match/#findComment-1213136 Share on other sites More sharing options...
ryancooper Posted May 10, 2011 Share Posted May 10, 2011 Pretty close. preg_match('/<body>(.*?)<\/body>/s', $content, $matches); Quote Link to comment https://forums.phpfreaks.com/topic/235971-preg_match/#findComment-1213141 Share on other sites More sharing options...
firedealer Posted May 10, 2011 Author Share Posted May 10, 2011 Thanks. I have update my code and still not working. ERROR MSG: Notice: Undefined variable: preg_match in /Applications/MAMP/htdocs/include/ip.php on line 6 Fatal error: Function name must be a string in /Applications/MAMP/htdocs/include/ip.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/235971-preg_match/#findComment-1213145 Share on other sites More sharing options...
fugix Posted May 10, 2011 Share Posted May 10, 2011 you need to remove the $ , try this <?php $content = "<html><head><title>Your IP</title></head><body>Your IP Address: 63.1.142.154</body></html>"; preg_match('/<body>(.*?)<\/body>/s', $content, $matches); print_r( $matches ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235971-preg_match/#findComment-1213151 Share on other sites More sharing options...
firedealer Posted May 10, 2011 Author Share Posted May 10, 2011 Aha! Thanks, it's working now. Quote Link to comment https://forums.phpfreaks.com/topic/235971-preg_match/#findComment-1213153 Share on other sites More sharing options...
fugix Posted May 10, 2011 Share Posted May 10, 2011 Aha! Thanks, it's working now. cool, glad i could help Quote Link to comment https://forums.phpfreaks.com/topic/235971-preg_match/#findComment-1213154 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.