You doubt to change data of an img

0

With the very good ones to the community, I have the following question, I am working on php and mysql. I need to change a part of a

<img src="http://localhost/upload/foto.jpg" width="259" height="194" />

I want to remove the width and the height from the img, because that will be handled from the css code, so that it is responsive and fits freely on the page. Like when you create a new article sometimes there are several images within the same article $ _ POST ['article'] , try to do it with explode but it does not work for me, and the same I would like to do with the

If you could help me I would appreciate it

<form method="POST">
<textarea name="articulo"></textarea>
</form>

therefore everything written in the textarea will be under tinymce.

<?php
$articulo=$_POST['articulo'];
//reemplazo algunos caracteres
$articulo=str_replace('<img src="../..', '<img src="http://localhost/", $articulo);

example: the $ article would come with the following - >

<p>este es un articulo para mostrar <img src="localhost/upload/foto.jpg" width="259" height="194" /></p>

here I need to do the elimination of the witdh and height that comes in the etiquieta     

asked by dogdark 23.08.2017 в 20:59
source

2 answers

1

If you want it, just remove the width and height to try this:

$cadena = '<p style="text-align: center;">esta es una imagen de prueba</p><p style="text-align: center;"><img src="upload/foto.jpg" alt="ee" width="25" height="194" /></p><p style="text-align: center;"><img src="upload/foto2.jpg" alt="" width="2" height="194" /></p><p style="text-align: center;">y con esto termino</p>';
$patrón = '/((width="([0-9])+")|(height="([0-9])+"))/i';
$sustitución = '';
echo preg_replace($patrón, $sustitución, $cadena);

I mean your code would be like this:

<?php
$articulo=$_POST['articulo'];
//reemplazo algunos caracteres
$articulo=str_replace('<img src="../..', '<img src="http://localhost/", $articulo);
$patrón = '/((width="([0-9])+")|(height="([0-9])+"))/i';
$articulo = preg_replace($patrón, '' , $articulo);
    
answered by 23.08.2017 / 22:40
source
0

HTML

The image should be directed from where it is stored, not from the url of localhost, change src by:

<img src="/upload/foto.jpg"/>

Do not forget that you must add the tag to apply responsively the attributes that you will apply in the image, in this case your css.

<meta content="width=device-width; initial-scale=1.0; name="viewport">

Finally in your css code, if you want the image to take 100% of the screen of the device you must assign the corresponding property:

CSS

img .upload {
width: 100%;
height: auto;

}

    
answered by 23.08.2017 в 21:51