0

I am making a svg uploader service. I want my clients able to upload svg files and the uploaded svg's are then displayed in their personal space.

Two types of svg are usually uploaded :

  • clean ones, the file's root element is already <svg>, no need to sanitize.
  • dirty ones, they are generated from softwares and contain extra headers.

I want to make a special treatment for the latter. removing the extra headers.

The dirty ones' first line is most of time a xml declaration. my question is how can i preg_match a xml declaration ?

at this moment, the file is contained in a variable $file.

I tried preg_match('/<\?xml/', $file) but this doesn't even seem to work.

vdegenne
  • 12,272
  • 14
  • 80
  • 106
  • 3
    SVG is an XML document - why not use XML parser? – Aleks G Apr 16 '15 at 11:01
  • @AleksG good point, however at this time my clients are only using illustrator. If the document contains xml headers, i know i only have to remove the three first lines. nothing too big as to use xml parsers. – vdegenne Apr 16 '15 at 11:03
  • See http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags. For the cleanup also see https://github.com/svg/svgo. – Erik Dahlström Apr 16 '15 at 12:33

0 Answers0