MsO MsO - 7 months ago 90
PHP Question

regex: Matching a javascript mime type in content-type http header

Looking for some way, I can verify the javascript content-type,

I have made

if(preg_match('/(text|application)\/javascript/i',$header){ #code ...


but this won't work all the cases because some servers reply with application/x-javascript

and my way verify application/javascript and text/javascript.

Answer

Your current answer is:

(text|application)\/(x-)?javascript

Will match x-javascript part too. Thats very small and basic change, I recommend you to study a bit more about regexp.
And you might find site regex101.com quite useful for your experiments.

Comments