Skip to content
Advertisement

Change iframe src with regex

I’m trying to change the src attribute of an iframe from http to https. For example, my string is:

JavaScript

What I need is to change it to

JavaScript

By far, I’ve been trying with preg_replace but no results:

JavaScript

Thank you

Advertisement

Answer

Try the following REGEX instead(DEMO):

JavaScript

But beware, You CAN NOT parse HTML with REGEX properly. Please, use some XML parser instead.

Also, it seems you only want to change http to https. So for that try the following instead:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement