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 Link to comment https://forums.phpfreaks.com/topic/47742-solved-simple-regex-help/ 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> Link to comment https://forums.phpfreaks.com/topic/47742-solved-simple-regex-help/#findComment-233187 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]+. Link to comment https://forums.phpfreaks.com/topic/47742-solved-simple-regex-help/#findComment-233824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.