Jump to content

replace image's width and height


aliento

Recommended Posts

Hi i have some images at my joomla which i want to change with regex.

The string is

<img src="img.png" width="300" height="300">


The width and the height is different every time.

 

i want to change width , height and to add and style="float:right" .

I think you can propose a regex to make it, or some other way to do it.

Its joomla site and the news module is not as i expected.

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/286345-replace-images-width-and-height/
Share on other sites

Its joomla site and the news module is not as i expected.

So you're using a Joomla Module to display news but you dont like how images are displayed on the page? I dont think you need regex is the answer. You just need to edit the template for that module to change how images are displayed.

I did it but it didn't work.

I found the code and i corrected it.

 

here is the code

<?php
$string = '<img src="" width="xx" height="yyy" alt="">';
$new_string = preg_replace('/\<(.*?)(width="(.*?)")(.*?)(height="(.*?)")(.*?)\>/i', '<$1$4$7>', $string);
echo $new_string;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.