Jump to content

[SOLVED] Simple regex help


robbyc

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.