Hello,
I want to parse some HTML code with PHP and REPLACE the SRC attribute of a <iframe>.
Example INPUT:
<iframe marginwidth="0" src=" marginheight="0" width="120" height="240" scrolling="no" frameborder="0" ></iframe>
OUTPUT should be for example:
<iframe marginwidth="0" src=" marginheight="0" width="120" height="240" scrolling="no" frameborder="0" ></iframe>
The real problem is that the SRC parameter can have double quotes (src=" single quotes (src=' or even no quotes at all (src=
Also it can be located within other attributes (like the code above) or at the end just before the closing tag > , for example:
<iframe width="120" height="240" src="
The code should be output exactly as input just with the SRC parameter replaced.
I tried using VARIOUS regular expressions but always it works just in some cases. For example I tried:
$pattern = "/<iframe ([^>]*)src=['\"]*([^'\s\">]*)['\"\s]+([^>]*)>(.*)<\/iframe>/Uis";
$pattern = "/<iframe ([^>]*)src=(.*)\s([^>]*)>(.*)<\/iframe>/Uis";
and others...
Any suggestions?
Many thanks,
c4n
I want to parse some HTML code with PHP and REPLACE the SRC attribute of a <iframe>.
Example INPUT:
<iframe marginwidth="0" src=" marginheight="0" width="120" height="240" scrolling="no" frameborder="0" ></iframe>
OUTPUT should be for example:
<iframe marginwidth="0" src=" marginheight="0" width="120" height="240" scrolling="no" frameborder="0" ></iframe>
The real problem is that the SRC parameter can have double quotes (src=" single quotes (src=' or even no quotes at all (src=
Also it can be located within other attributes (like the code above) or at the end just before the closing tag > , for example:
<iframe width="120" height="240" src="
The code should be output exactly as input just with the SRC parameter replaced.
I tried using VARIOUS regular expressions but always it works just in some cases. For example I tried:
$pattern = "/<iframe ([^>]*)src=['\"]*([^'\s\">]*)['\"\s]+([^>]*)>(.*)<\/iframe>/Uis";
$pattern = "/<iframe ([^>]*)src=(.*)\s([^>]*)>(.*)<\/iframe>/Uis";
and others...
Any suggestions?
Many thanks,
c4n