php - How to remove a data uri from text using a regular expression? -
What is a great way to remove data URI from a block of text with regular expression ? My application has to be removed from email body texts because Amazon SES (Simple Email Service) rejects any email with data URI. . They should also be removed for security purposes Example data URI: It can be surrounded by quotes such as HTML: Or this can be a CSS background: This should do the trick:
data: image / gif; Base 64, R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o / XBs / fNwfjZ0frl3 / zy7 //// wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7
& lt ; img src = "data: image / gif; base64, R0lGODlhEAAQA ...." / & gt;
Background: URL (Data: Image / GIF; Base64, RLGODLAAAAAAAAA ... .);
$ Regex = '~ Data: [^;] +; [E-za-j 0-9] +, [^] \ '\ s] + ~'; $ Body = preg_replace ($ regex, '', $ body);
Comments
Post a Comment