|
Posted by Peter on 09/05/07 13:15
Hi,
I parse some text an make alterations. The text is machine generated and
always the same in syntax and layout, so that makes things a bit easier.
One of the alterations is that I want to remove the WIDTH and HEIGHT from
<IMG> data. So that I can easily change images on the server (different
sizes) without having to alter the html again.
Following works for me:
$help_body = preg_replace ("/WIDTH=\"(.*)\" HEIGHT=\"(.*)\" BORDER=\"0\"/",
" BORDER=\"0\"", $help_body);
BUT ... I just noticed that it doesn't work when there are two images
sitting next to each other on the same line.
The reason seems to be that the preg_replace finds as much as possible
between 'HEIGHT' and 'BORDER', inclusive another 'HEIGHT' and 'BORDER' on
the same line.
How do I manipulate it so that the preg_replace works for both <IMG>
instances on the same line ?
Example:
<FONT FACE="Arial, helvetica, sans-serif" COLOR="#800000" SIZE="2"><IMG
SRC="PIC1.png" WIDTH="308" HEIGHT="328" BORDER="0"> <IMG SRC="PIC2.png"
WIDTH="312" HEIGHT="329" BORDER="0"></FONT><BR>
Is converted to:
<FONT FACE="Arial, helvetica, sans-serif" COLOR="#800000" SIZE="2"><IMG
SRC="PIC1.png" BORDER="0"></FONT><BR>
instead of:
<FONT FACE="Arial, helvetica, sans-serif" COLOR="#800000" SIZE="2"><IMG
SRC="PIC1.png" BORDER="0"> <IMG SRC="PIC2.png" BORDER="0"></FONT><BR>
Some guru intel appreciated.
Navigation:
[Reply to this message]
|