首页 > 解决方案 > 即使不是特殊字符,某些单词也不会在 PHP 中显示

问题描述

我有这个奇怪的问题,我正在通过 Xammp 服务器从 SQL Server 检索数据并通过浏览器在 PHP 中显示(通过 json 输出),所以我想在浏览器中显示的一些字符串有描述,例如

"**Delightfully warmingour butterysweet tart crusts are filled with delicious fillings Try the lemontart for a slice of sweet and tangy flavour**" 

和另一个例子

" **Richwarm and homemadeour chocolate brownie has a fudgy inside and a crisp chocolaty outside  served with a scoop of VANILLA ICE CREAM Rs 430**" 

当我通过 PHP 从数据库中检索时,不会在浏览器中显示,因为您可以看到没有特殊字符(逗号“,”除外),但即使带有“,”,它也会显示在一些描述中,但特别是以上两个示例未在浏览器中显示。

我不明白为什么,这很奇怪,任何人都可以帮助我解决这个问题,在这方面的帮助将不胜感激,

PHP代码如下:

<?php
    //require_once(dirname(__FILE__).'/connectionInfoTest.php');
    require_once(dirname(__FILE__).'/connectionInfoTestNew.php');

{
    //Set up our connection
    $connectionInfo = new ConnectionInfo();
    $connectionInfo->GetConnection();

    if (!$connectionInfo->conn) {
        //Connection failed
        echo 'No Connection';
    } else {

        $query = " SELECT i.itemid as fir_ID,i.name as fir_name,
                    i.code, i.itemdescription,i.unitprice,i.isservicecharge,
                    i.costprice,i.itemgroupid,i.image,c2.name as sec_name 
                    FROM vw_app_item i 
                        inner join itemlayer1 c1 on i.itemlayer1id = c1.itemlayer1id 
                        inner join itemlayer2 c2 on i.itemlayer2id=c2.itemlayer2id 
                    WHERE c2.name in ('ICED TEA','BLACK TEA','MOCKKTAIL',
                                        'SPARKLING TEA','T-SHAKES','SMOOTHIE',
                                        'WATTE','BRUSCHETTA','BRUSCHETTA','CREPE',
                                        'BURGER','DESSERT','ICE CREAM',
                                        'PIZZA','TOASTIE','WAFFLE','WRAP','TACO') 
                    order by c1.name,c2.name";  // query to check the all the categories


        $stmt = sqlsrv_query($connectionInfo->conn, $query);

        if (!$stmt)
        {
            //Query failed
            echo 'Query failed';
        } else {
            $contacts = array(); //Create an array to hold all of the contacts
            //Query successful, begin putting each contact into an array of contacts

            while ($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC)) //While there are still contacts
            {
                //Create an associative array to hold the current contact
                //the names must match exactly the property names in the contact class in our C# code.
                $contact= array("ID" => $row['fir_ID'],
                                 "Category" => $row['sec_name'],
                                 "Name" => $row['fir_name'],
                                 "Code" => $row['code'],
                                 "Description" => $row['itemdescription'],
                                 "Price" => $row['unitprice'],
                                 "isservicecharge" => $row['isservicecharge'],
                                 "CostPrice" => $row['costprice'],
                                 "Date" => $row['itemgroupid'],                              
                                 "Image" => base64_encode($row['image'])                                                                                                 
                                 );                                  
                //Add the contact to the contacts array
                array_push($contacts, $contact);
            }

            //Echo out the contacts array in JSON format
            header('Content-type: application/json');
            $output = ['Resturent' => $contacts];
            echo json_encode($output, JSON_PRETTY_PRINT);
        }
    }
}
?>

标签: phpjsonsql-serverxampp

解决方案


其实是item source中的空格产生的问题,就数据库而言,数据库中的数据应该存储在中间没有空格。


推荐阅读