duanchai0028 2014-09-06 09:09
浏览 82

如何在MYSQL中查找和替换在数据库中有<>“'的字符串?

i'm not an expert in mysql but i need to find and replace the data

<h2 class="ui-box-title">Product Description</h2>
   <div class="ui-box-body">
     <p> &nbsp; </p> <h2 style="padding: 5.0px;">


  <div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;"> 

i try to use this command

SELECT * 
FROM  `oc_product_description` 
WHERE  `description` LIKE '%<h2 class="ui-box-title">Product Description</h2>    <div class="ui-box-body">      <p> &nbsp; </p> <h2 style="padding: 5.0px;">     <div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;"> %'
LIMIT 0 , 30

but it return 0 results

i need to find and replace the value with "" in my table description how to do that? and if i search using this command

SELECT * 
FROM  `oc_product_description` 
WHERE  `description` LIKE  '% <h2 class="ui-box-title">Product Description</h2>%'
LIMIT 0 , 30

it will return the results Showing rows 0 - 29

please advise need help from expert. appreciated. thanks

  • 写回答

2条回答 默认 最新

  • douhui4699 2014-09-06 09:17
    关注

    Why your code is not working

    Spacing of the code in database may be different from the given one.

    Solution

    You could do something like this:

    <?php
    $1 = '<h2 class="ui-box-title">Product Description</h2>';
    $2 = '<div class="ui-box-body">';
    $3 = '<p> &nbsp; </p> <h2 style="padding: 5.0px;">';
    $4 = '<div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;">';
    $connect= mysqli_connect("localhost","root","","db"); //edit parameters
    $query = "SELECT * 
    FROM  `oc_product_description` 
    WHERE  `description` LIKE '%".$1."%' AND `description` LIKE '%".$2%."'`description` LIKE '".%$3%."' AND `description` LIKE '%".$4%."'
    LIMIT 0 , 30";
    $query = mysqli_query($connect,$query);
    if(mysqli_num_rows($query)==1){echo 'Found the correct string!<br>';
    $assoc = mysqli_fetch_assoc($query);
    echo $assoc['description'];
    }
    else if(mysqli_num_rows($query)>1){echo 'Found too much results!';}
    else{echo 'Found nothing!';}
    ?>
    

    If this doesn't work anyway

    You could have escaped html strings before the insertion in the database. Replace

    $1 = '<h2 class="ui-box-title">Product Description</h2>';
    $2 = '<div class="ui-box-body">';
    $3 = '<p> &nbsp; </p> <h2 style="padding: 5.0px;">';
    $4 = '<div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;">';
    $connect= mysqli_connect("localhost","root","","db"); //edit parameters
    

    With

    $connect= mysqli_connect("localhost","root","","db"); //edit parameters
    $1 = mysqli_real_escape_string($connect,'<h2 class="ui-box-title">Product Description</h2>');
    $2 = mysqli_real_escape_string($connect,'<div class="ui-box-body">');
    $3 = mysqli_real_escape_string($connect,'<p> &nbsp; </p> <h2 style="padding: 5.0px;">');
    $4 = mysqli_real_escape_string($connect,'<div style="max-width: 650.0px;overflow: hidden;font-size: 0;clear: both;"><div style="border: 1.0px solid #dedede;vertical-align: top;text-align: left;color: #666666;width: 120.0px;padding: 10.0px 15.0px;margin: 10.0px 10.0px 0 0;word-break: break-all;display: inline-block;">');
    

    If you still don't get the expected result, it is possible that you had used htmlspecialchars(), maybe in addition to mysqli_real_escape_string().
    Edit variables $1,$2,$3 and $4 adding htmlspecialchars, if it doesn't work try to remove mysqli_real_escape_string.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。