Tommienbp
asked on
Regexp problem in PHP
Hello,
I've got a large area of plain HTML code. I want to filter out all the <IMG> tags which look like this:
<IMG id=64_1 onresize="parent.resize(th is,'198',' 198')" style="WIDTH: 198px; HEIGHT: 198px" alt="" src="http://www.domain.nl/sre/data/origineel/64_1.jpg">
Of this tag I want to filter out the height, width and id and put this in a variable.
Next I want to replace the whole tag with:
<IMG id=64_1 alt="" src="http://www.domain.nl/sre/data/64_1.jpg"> and put it back in the HTML code.
I want to do this for all Image tags in the document.
Is it possible to put all image tags in an array and check/change them all?
Sorry for my bad english and thanks for any help or suggestions. Tom
I've got a large area of plain HTML code. I want to filter out all the <IMG> tags which look like this:
<IMG id=64_1 onresize="parent.resize(th
Of this tag I want to filter out the height, width and id and put this in a variable.
Next I want to replace the whole tag with:
<IMG id=64_1 alt="" src="http://www.domain.nl/sre/data/64_1.jpg"> and put it back in the HTML code.
I want to do this for all Image tags in the document.
Is it possible to put all image tags in an array and check/change them all?
Sorry for my bad english and thanks for any help or suggestions. Tom
The following regexp will match any image tag which contains the elements you've shown (id, onresize, alt, src)
<IMG ID=(.*) onresize=(.*) style=(.*) alt=(.*) src=(.*)>
Each sub-pattern can then be checked in turn.
You can then create a new output string of ...
<img id=\1 alt=\4 src=\5>
Richard.
<IMG ID=(.*) onresize=(.*) style=(.*) alt=(.*) src=(.*)>
Each sub-pattern can then be checked in turn.
You can then create a new output string of ...
<img id=\1 alt=\4 src=\5>
Richard.
Doing this as a one off task for all the files in a site, I would recommend a 30 day trial product (as suggested by bmarlin). The amount of time it would take to do 90% would probably be a few minutes and then the rest would be done by hand or by a more refined search/replace.
Richard.
Richard.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot, that will do the trick in the future too. :)
All I do is if I am replacing a GLOBAL variable where it is the same throughout the program I just hit ctrl + r It is like the find command but you enter what you are replacing and what with. Then you can do it by each variable or check globally.
http://www.premia.com/download/
You can get a 30 day trial copy here.
However if each one of the <img... is different you might just have to replace what is the same in all of them and then go back and edit.
Not sure if this is your best solution but if they are all the same its a 3 step process.