Stephen Posted June 25, 2009 Share Posted June 25, 2009 I am trying to parse something that looks like this: <style type="text/css">/*\*/@import url(http://www.site.com/css/global.css);/**/</style> <style type="text/css">/*\*/@import url(http://www.site.com/css/home.css);/**/</style> and retrieve just the URL contained in the parenthesis. However, every regex expression I've tried fails, such as /<style\s[^>]*>\/\*\\\*\/@import url\(\s[^>]*\);\/\*\*\/<\/style>/ Please note that I completely fail at regex and any expression that actually works will be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/163681-solved-parse-import-url/ Share on other sites More sharing options...
rhodesa Posted June 25, 2009 Share Posted June 25, 2009 <?php $html = <<<HTML <style type="text/css">/*\*/@import url(http://www.site.com/css/global.css);/**/</style> <style type="text/css">/*\*/@import url(http://www.site.com/css/home.css);/**/</style> HTML; if(preg_match_all('/<style\s[^>]*>\\/\\*\\\\\*\\/@import url\(([^>]*?)\);\\/\\*\\*\\/<\\/style>/',$html,$matches)){ foreach($matches[1] as $url){ print $url.'<br />'; } }else{ print "No matches"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163681-solved-parse-import-url/#findComment-863640 Share on other sites More sharing options...
Stephen Posted June 25, 2009 Author Share Posted June 25, 2009 Thank you, rhodesa Quote Link to comment https://forums.phpfreaks.com/topic/163681-solved-parse-import-url/#findComment-863643 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.