gpt4 book ai didi

php - json_encode 不编码长字符串

转载 作者:搜寻专家 更新时间:2023-10-31 22:10:57 24 4
gpt4 key购买 nike

在我的脚本中,json_enocode 正在编码字符串或者可能存在其他问题?

首先让我展示一下我的配置和代码中的所有东西

表结构

CREATE TABLE `dc_songs` (
`songs_id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`song_name` varchar(2000) NOT NULL,
`lyrics` text NOT NULL,
`created_time` datetime NOT NULL,
`is_deleted` tinyint(4) NOT NULL,
`delete_reason` text NOT NULL,
PRIMARY KEY (`songs_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1

这是我在给定表格的一行中更新的字符串

UPDATE `dc_songs` SET `lyrics` = 'Your account privacy is very important to us. You are like our family member. You can manage all your content via privacy settings. Content with privacy settings public visible to every user of this web site. You must read how content will be displayed according to your privacy in Help Section. 2.Safety

We do our best keep this web site safe but this not always depend on us, for that you will need to follow this safety Rules.

You will not post content that is copyrighted or Unauthorized
You will not use someone’s account
You will not irritate users in anyways.
You will not upload content like virus or spam.
You will not share content that can hate someone, threatening, or pornographic.
You will not do act that can affect this web site.
You must provide all your original details.
You will not use, download or share someone’s content like personal information, photographs, videos or any other that is not yours.
You will not force user to do act that make our samaj down.
You will not force user to fight against your enemy.
You will not encourage people to do violence.
You will not use this web site to do anything unlawful, misleading, malicious, or discriminatory. ' WHERE `dc_songs`.`songs_id` = 2;

查询我正在使用

$query = "SELECT songs_id,lyrics,s.username,song_name,p.fullname
FROM dc_songs s
LEFT JOIN profile p ON p.username=s.username
ORDER by songs_id DESC";
$r=$db->run($query);

在编码 $r 之后我得到了这个输出

[{"songs_id":"2","lyrics":null,"username":"bhavik","song_name":"some name 1","fullname":"Bhavik Thakor Garasiya"} ]

更新:

print_r($r) 的输出;

Array ( [0] => Array ( [songs_id] => 2 [lyrics] => Your account privacy is very important to us. You are like our family member. You can manage all your content via privacy settings. Content with privacy settings public visible to every user of this web site. You must read how content will be displayed according to your privacy in Help Section. 2.Safety We do our best keep this web site safe but this not always depend on us, for that you will need to follow this safety Rules. You will not post content that is copyrighted or Unauthorized You will not use someone’s account You will not irritate users in anyways. You will not upload content like virus or spam. You will not share content that can hate someone, threatening, or pornographic. You will not do act that can affect this web site. You must provide all your original details. You will not use, download or share someone’s content like personal information, photographs, videos or any other that is not yours. You will not force user to do act that make our samaj down. You will not force user to fight against your enemy. You will not encourage people to do violence. You will not use this web site to do anything unlawful, misleading, malicious, or discriminatory. [username] => bhavik [song_name] => some name 1 [fullname] => Bhavik Thakor Garasiya ) ) 

最佳答案

我进行了一些测试,这个字符 ' 似乎破坏了文本的 json 编码。

这是我用来测试数据的脚本。第一部分尝试按照提供的方式对文本进行编码,然后 ' 字符被 ' 替换,编码工作正常。

<?php
$json = array('data' => htmlentities('Your account privacy is very important to us. You are like our family member. You can manage all your content via privacy settings. Content with privacy settings public visible to every user of this web site. You must read how content will be displayed according to your privacy in Help Section. 2.Safety

We do our best keep this web site safe but this not always depend on us, for that you will need to follow this safety Rules.

You will not post content that is copyrighted or Unauthorized
You will not use someone’s account
You will not irritate users in anyways.
You will not upload content like virus or spam.
You will not share content that can hate someone, threatening, or pornographic.
You will not do act that can affect this web site.
You must provide all your original details.
You will not use, download or share someone’s content like personal information, photographs, videos or any other that is not yours.
You will not force user to do act that make our samaj down.
You will not force user to fight against your enemy.
You will not encourage people to do violence.
You will not use this web site to do anything unlawful, misleading, malicious, or discriminatory. '));

echo '<pre>';
echo json_encode($json);
echo "\n";

$json['data'] = str_replace('’', "'", $json['data']);

echo json_encode($json);
echo '</pre>';
?>

这是输出:

{"data":null}
{"data":"Your account privacy is very important to us. You are like our family member. You can manage all your content via privacy settings. Content with privacy settings public visible to every user of this web site. You must read how content will be displayed according to your privacy in Help Section. 2.Safety\r\n\r\nWe do our best keep this web site safe but this not always depend on us, for that you will need to follow this safety Rules.\r\n\r\n You will not post content that is copyrighted or Unauthorized\r\n You will not use someone's account\r\n You will not irritate users in anyways.\r\n You will not upload content like virus or spam.\r\n You will not share content that can hate someone, threatening, or pornographic.\r\n You will not do act that can affect this web site.\r\n You must provide all your original details.\r\n You will not use, download or share someone's content like personal information, photographs, videos or any other that is not yours.\r\n You will not force user to do act that make our samaj down.\r\n You will not force user to fight against your enemy.\r\n You will not encourage people to do violence.\r\n You will not use this web site to do anything unlawful, misleading, malicious, or discriminatory. "}

关于php - json_encode 不编码长字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13074969/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com