Home > Backend Development > PHP Tutorial > PHP string replacement to implement image adaptive screen example code

PHP string replacement to implement image adaptive screen example code

小云云
Release: 2023-03-21 07:14:01
Original
3141 people have browsed it

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);;
        }?>
Copy after login

Related recommendations:

JS to achieve automatic carousel effect (adaptive screen width + mobile phone touch screen sliding)_javascript skills

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template