php - 即使不是特殊字符,某些单词也不会在 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);
}
}
}
?>
解决方案
其实是item source中的空格产生的问题,就数据库而言,数据库中的数据应该存储在中间没有空格。
推荐阅读
- linq - 我如何知道我的 linq 是否会返回可用对象或 null
- azure - 使用多个包服务器部署到 Azure 网站
- asp.net-core - EF Code First Migrations 突然停止申请
- python - Cloudflare API 默认代理参数为 false
- memory - 如何从 erlang 崩溃转储中找到内存泄漏进程?
- php - 有人可以向我解释 PHP SQL Select 数据吗?
- android - 布局预览在 android studio 3.4.1 中不起作用
- laravel - Laravel:$errors->first() 不显示错误。如何让它发挥作用?
- automation - 正则表达式 (0+1)*1(0+1)*0 DFA
- css - 如何将 CSS 类添加到 Flask-Table 列