regex - how can i preg_match a xml declaration using php?


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 ipreg_match a xml declaration ?

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

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

People are also looking for solutions to the problem: php - Pagination not working with WP_query


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.