robbyc Posted April 19, 2007 Share Posted April 19, 2007 I have an XML document from which I want to strip out the style sheet tag. Example below <?xml-stylesheet title="XSL_formatting" type="text/xsl" href="/shared/bsp/xsl/rss/nolsol.xsl"?> I am guessing i need a regex which will match ¨<?xml-stylesheet anything in between ?>¨ but I am terrible at regular expressions. Any help will be greatly appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
effigy Posted April 19, 2007 Share Posted April 19, 2007 This will remove any preceding space, the tag itself, and any following line endings: <pre> <?php $xml = <<<XML <?xml-stylesheet title="XSL_formatting" type="text/xsl" href="/shared/bsp/xsl/rss/nolsol.xsl"?> <root> ... </root> XML; echo preg_replace('/\s*<\?xml-stylesheet.+?\?>[\r\n]+/', '', $xml); ?> </pre> Quote Link to comment Share on other sites More sharing options...
robbyc Posted April 20, 2007 Author Share Posted April 20, 2007 Thanks that's great although it would not work until I took out [\r\n]+. 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.