PHP - 如何从数据库中删除双引号?

时间:2017-01-17 10:11:43

标签: php jquery html

我将数据存储在数据库文本字段中,如下所示:

<p><strong>Relish Scrumptious Dessert Delights with Baskin Robbins Gift
 Voucher</strong></p><span>good</span><div>any rendom text</div> and so on..

所以现在当我在前端打印这些数据时,它应该删除HTML标签只显示字段的主要内容但不是,它显示了我存储在数据库中的相同数据,因为它正在服用它作为一个字符串意味着当我从数据库中提取数据时,它会在数据的开头和结尾添加双引号,以便将其作为字符串读取并显示给我与数据库中的数据相同。

我使用inspect元素进行检查并显示它会自动添加双引号,以便测试我已使用inspect元素删除双引号并且所有数据都正确显示。

我尝试在页面加载时使用jquery用空格替换双引号,但我的实际数据不包含任何双引号,因此jquery函数不会替换任何内容

我努力解释我的问题,我希望你们能理解我的问题,有人让我知道我面临的这个奇怪问题的解决方案。

  

UPDAT

BrandController.php

public function get_brand_api(){


$select = "SELECT
               b.*,
               GROUP_CONCAT(bp.p_name) AS price,
               GROUP_CONCAT(bp.p_skuId) AS sku,
               GROUP_CONCAT(bp.p_type) AS type,
               GROUP_CONCAT(bp.p_valueType) AS valuetype
               FROM
               brands AS b
               LEFT JOIN
               brand_price AS bp ON b.hash = bp.hash
               WHERE b.slug = :slug GROUP BY  b.brand_id
               ";
    $sth = $this->connection->prepare($select);
    $sth->bindParam(":slug", $slug);
    $sth->setFetchMode(PDO::FETCH_ASSOC);
    $sth->execute();
    $status = $sth->fetchAll();

    return $status;


}

brand_detail.blade.php

<div id="container_detail">
  <brand-detail></brand-detail>
</div>
<template id="brand-detail-template">
   <div class="content">
      <h1> @{{d.brand_name}} </h1>
      <img :src="d.image" class="">     
   </div>
    @{{d.description}} // HERE I AM GETTING HTML TAGS WITH DATA.
</template>

brand_detail.js

Vue.component('brand-detail', {

template: '#brand-detail-template',

data: function(){

return {

    detail: []

}

},

created: function(){
//var slug = this.$route.params.slug;
var slug = window.location.pathname.split("/").pop();
var url = window.location.protocol + "//" + window.location.host + "/";

var api_url = url + 'gift_india/brand_detail/' + slug;
var that = this
axios.get(api_url)
    .then(function (response) {
        //console.log(response.data);
        that.detail = response.data;

    })
    .catch(function (error) {
        console.log(error.data);
    });

    },

   filters: {
removehtml: function (value) {
    if (!value) return ''
    var myContent = value;
    return myContent.replace(/(<([^>]+)>)/ig,"");
},
strtoarr: function (value) {

    var array = JSON.parse("[" + value + "]");
    return array;
}


}



});



 new Vue({



 el: '#container_detail'



 })

以上刀片模板代码与Vue js相关,因此有一些rendom标签和模板。

2 个答案:

答案 0 :(得分:0)

如果您要删除标记,可以使用strip tags功能

echo strip_tags($text);

如果要替换双引号,并将其视为HTML,请使用以下代码。

$html = str_replace('"', '', $text);

答案 1 :(得分:0)

使用str_replace删除字符串中的所有双引号。

$data = str_replace('"', '', $text);