aliento Posted February 20, 2014 Share Posted February 20, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/286345-replace-images-width-and-height/ Share on other sites More sharing options...
Ch0cu3r Posted February 20, 2014 Share Posted February 20, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/286345-replace-images-width-and-height/#findComment-1469698 Share on other sites More sharing options...
aliento Posted February 20, 2014 Author Share Posted February 20, 2014 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/286345-replace-images-width-and-height/#findComment-1469700 Share on other sites More sharing options...
.josh Posted February 20, 2014 Share Posted February 20, 2014 well that's not really replacing the width and height.. it's removing it. Quote Link to comment https://forums.phpfreaks.com/topic/286345-replace-images-width-and-height/#findComment-1469704 Share on other sites More sharing options...
aliento Posted February 20, 2014 Author Share Posted February 20, 2014 and then i put $string = str_replace('<img','<img width="90px" height="90px"',$string); Quote Link to comment https://forums.phpfreaks.com/topic/286345-replace-images-width-and-height/#findComment-1469705 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.