codingmasterRS Posted July 18, 2010 Share Posted July 18, 2010 So I want to use PHP and preg_replace to delete all contents of a string between "/*" and "*/". $file = file_get_contents('fg.menu.css'); echo preg_replace('', $file); just need to know what to put between the '' in preg_replace Thanks in advance Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 18, 2010 Share Posted July 18, 2010 Depends upon the rules and what can be in between the /* and */ and other things but this is a simple one: echo preg_replace('#/\*(.*)?\*/#s', '', $file); Quote Link to comment Share on other sites More sharing options...
codingmasterRS Posted July 18, 2010 Author Share Posted July 18, 2010 anything can be between /* and */ would you be able to alter your same based on the above condition Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 18, 2010 Share Posted July 18, 2010 Did you try your inputs on what I posted? Quote Link to comment Share on other sites More sharing options...
codingmasterRS Posted July 18, 2010 Author Share Posted July 18, 2010 it needs to do for anything between /* and */ Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 18, 2010 Share Posted July 18, 2010 it needs to do for anything between /* and */ OK, and what is not working??? Give an input, expected result and actual result. Quote Link to comment Share on other sites More sharing options...
codingmasterRS Posted July 18, 2010 Author Share Posted July 18, 2010 index.php $file = file_get_contents('fg.menu.css'); echo preg_replace('', $file); fg.menu.css /* Styles for jQuery menu widget Author: Maggie Wachs, maggie@filamentgroup.com Date: September 2008 */ /* REQUIRED STYLES - the menus will only render correctly with these rules */ .nav-menu-container { position: absolute; top:0; left:-999px; padding: .4em; overflow: hidden; } .nav-menu-container.nav-menu-flyout { overflow: visible; } .nav-menu, .nav-menu ul { list-style-type:none; padding: 0; margin:0; } .nav-menu { position:relative; } .nav-menu-flyout .nav-menu { position:static; } .nav-menu ul { position:absolute; top:0; } .nav-menu ul ul { top:-1px; } .nav-menu-container.nav-menu-ipod .nav-menu-content, .nav-menu-container.nav-menu-ipod .nav-menu-content ul { background: none !important; } .nav-menu.nav-menu-scroll, .nav-menu ul.nav-menu-scroll { overflow: scroll; overflow-x: hidden; } .nav-menu li { clear:both; float:left; width:100%; margin: 0; padding:0; border: 0; } .nav-menu li li { font-size:1em; } /* inner li font size must be reset so that they don't blow up */ .nav-menu-flyout ul ul { padding: .4em; } .nav-menu-flyout li { position:relative; } .nav-menu-scroll { overflow: scroll; overflow-x: hidden; } .nav-menu-breadcrumb { margin: 0; padding: 0; } .nav-menu-footer { margin-top: .4em; padding: .4em; } .nav-menu-header { margin-bottom: .4em; padding: .4em; } .nav-menu-breadcrumb li { float: left; list-style: none; margin: 0; padding: 0 .2em; font-size: .9em; opacity: .7; } .nav-menu-breadcrumb li.nav-menu-prev-list, .nav-menu-breadcrumb li.nav-menu-current-crumb { clear: left; float: none; opacity: 1; } .nav-menu-breadcrumb li.nav-menu-current-crumb { padding-top: .2em; } .nav-menu-breadcrumb a, .nav-menu-breadcrumb span { float: left; } .nav-menu-footer a:link, .nav-menu-footer a:visited { float:left; width:100%; text-decoration: none; } .nav-menu-footer a:hover, .nav-menu-footer a:active { } .nav-menu-footer a span { float:left; cursor: pointer; } .nav-menu-breadcrumb .nav-menu-prev-list a:link, .nav-menu-breadcrumb .nav-menu-prev-list a:visited, .nav-menu-breadcrumb .nav-menu-prev-list a:hover, .nav-menu-breadcrumb .nav-menu-prev-list a:active { background-image: none; text-decoration:none; } .nav-menu-breadcrumb .nav-menu-prev-list a { float: left; padding-right: .4em; } .nav-menu-breadcrumb .nav-menu-prev-list a .nav-menu-uiicon { float: left; } .nav-menu-breadcrumb .nav-menu-current-crumb a:link, .nav-menu-breadcrumb .nav-menu-current-crumb a:visited, .nav-menu-breadcrumb .nav-menu-current-crumb a:hover, .nav-menu-breadcrumb .nav-menu-current-crumb a:active { display:block; background-image:none; font-size:1.3em; text-decoration:none; } /* REQUIRED LINK STYLES: links are "display:block" by default; if the menu options are split into selectable node links and 'next' links, the script floats the node links left and floats the 'next' links to the right */ .nav-menu a:link, .nav-menu a:visited, .nav-menu a:hover, .nav-menu a:active { float:left; width:92%; padding:.3em 3%; text-decoration:none; outline: 0 !important; } .nav-menu a { border: 1px dashed transparent; } .nav-menu a.nav-menu-uistate-default:link, .nav-menu a.nav-menu-uistate-default:visited, .nav-menu a.nav-menu-uistate-default:hover, .nav-menu a.nav-menu-uistate-default:active, .nav-menu a.nav-menu-uistate-hover:link, .nav-menu a.nav-menu-uistate-hover:visited, .nav-menu a.nav-menu-uistate-hover:hover, .nav-menu a.nav-menu-uistate-hover:active, .nav-menu a.nav-menu-uistate-active:link, .nav-menu a.nav-menu-uistate-active:visited, .nav-menu a.nav-menu-uistate-active:hover, .nav-menu a.nav-menu-uistate-active:active { border-style: solid; font-weight: normal; } .nav-menu a span { display:block; cursor:pointer; } /* SUGGESTED STYLES - for use with jQuery UI Themeroller CSS */ .nav-menu-indicator span { float:left; } .nav-menu-indicator span.nav-menu-uiicon { float:right; } .nav-menu-content.nav-menu-uiwidget-content, .nav-menu-content ul.nav-menu-uiwidget-content { border:0; } /* ICONS AND DIVIDERS */ .nav-menu.nav-menu-has-icons a:link, .nav-menu.nav-menu-has-icons a:visited, .nav-menu.nav-menu-has-icons a:hover, .nav-menu.nav-menu-has-icons a:active { padding-left:20px; } .nav-menu .horizontal-divider hr, .nav-menu .horizontal-divider span { padding:0; margin:5px .6em; } .nav-menu .horizontal-divider hr { border:0; height:1px; } .nav-menu .horizontal-divider span { font-size:.9em; text-transform: uppercase; padding-left:.2em; } So it should remove all the comments (the stuff between /* and */) Then it needs to get all the stuff between { and } and number to an array relative to their tag, so: .nav-menu-container = $tag[1] and position: absolute; top:0; left:-999px; padding: .4em; overflow: hidden; = $contents[1] etc Thanks Quote Link to comment Share on other sites More sharing options...
codingmasterRS Posted July 18, 2010 Author Share Posted July 18, 2010 bump Quote Link to comment Share on other sites More sharing options...
codingmasterRS Posted July 21, 2010 Author Share Posted July 21, 2010 bump Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 21, 2010 Share Posted July 21, 2010 Despite the obnoxious bumping, here is workable code: $file = file_get_contents('fg.menu.css'); $file = preg_replace('#/\*.*?\*/#s', '', $file); preg_match_all('#(\b[^{]+){[^}]+}#', $file, $tag); $tag = $tag[1]; preg_match_all('#{([^}]+)}#', $file, $content); $content = $content[1]; print_r($tag); print_r($content); Quote Link to comment Share on other sites More sharing options...
codingmasterRS Posted July 24, 2010 Author Share Posted July 24, 2010 Thanks, but this is getting rid of the "." or "#" at the beginning of the tag otherwise all good, so if we can just fix this one problem Quote Link to comment 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.