I want to replace all href elements which contain url with file zip or pdf for example:
text = lorem inpsut http://example.com/file/file.zip lorem inspus https://example.com/file/file2.zip lorem inpus a lorem inpust http://example.com/file/file3.doc
and now i want to replace all this link to other link using preg_replace so:
http://example.com/file/file.zip - replace
https://example.com/file/file2.zip - replace
http://example.com/file/file3.doc - no replace beacuse .doc
https://example.com/file/testzip - no replace because testzip not .zip
https://example.com/file/dafsf.aszip - no replace
I figured out one:
/(\bhttps?\:\/\/|\/\/)\S+(?:.zip|.pdf)\b/gim
but it doesn't work corectly beacuse it finding also
https://example.com/file/file2.aaazip and
https://example.com/file/dafsfaszip
Could you help me?
Aucun commentaire:
Enregistrer un commentaire