Today, when I read the product details information field from the database, it was not a string. If I input it using echo, the web page would be directly parsed into HTML format, so I couldn't go to the Android side to operate the string, so I thought of doing it on the server side. , in the following code, three things are done respectively. The first is to read the field content, the second is to replace the useless string and set the width of the picture, and the third is to modify the target field to the picture.
<?php$cnn=mysqli_connect("localhost","root","kz5DdksQyE","rooot"); //连接数据库$bm="set names utf8"; //商品ID$id=$_GET["id"];$sql = "SELECT * FROM `vi_items` WHERE `id` = $id";$ccc=mysqli_query($cnn,$sql);//执行代码 //遍历一下数据库内容 while($arr = mysqli_fetch_assoc($ccc)){ //获取数据库中所需字段 $urmes = $arr["desc"]; //替换无用字符串并且设置图片的宽度 $diyic = str_replace("src=/data/upload/site/58fd01e4a1f22.png","width=100%",$urmes); //修改目标字段为图片 echo str_replace("src","src",$diyic);; }?>
Related recommendations:
About the problem of referencing external CSS files to adapt to the screen_html/css_WEB-ITnose
##About HTML, css3 adaptive screen, adaptive width_html/ css_WEB-ITnose
The above is the detailed content of PHP string replacement to implement image adaptive screen example code. For more information, please follow other related articles on the PHP Chinese website!