简体   繁体   中英

Json encode of string in php returning false

array(12) {
  ["id"]=>
  string(4) "9033"
  ["title"]=>
  string(25) "Let There Be Life! Easter"
  ["body"]=>
  string(2589) "<p>Good Friday!</p><p>&nbsp_Hell is not a place God sends people that he is mad at.</p><p>&nbsp_Hell is a place for those people who choose to pay their own bill.</p><p>&nbsp_WHY DID JESUS NEED TO RISE FROM THE DEAD?</p><p>&nbsp_&nbsp_&nbsp_&nbsp_To prove He really is who He claimed to be.</p><p><strong>Acts 1:3 NIV</strong></p><p>&nbsp_&nbsp_To Conquer death for Himself and for US!</p><p>&nbsp_POWER THAT WAS ATTAINED FOR US TO COME ALIVE AS WELL AS HIM.</p><p><strong>Revelation 1:18 NKJV</strong></p><p>SATAN WAS SO CAUGHT UP IN KILLING JESUS, THAT HE HAD NOT CONSIDERED WHAT TO DO ONCE GOD WAS ALLOWED INTO HIS HELL.</p><p>&nbsp_You have had the Friday understanding but you have never really walked in the victory of the Sunday part of Easter.</p><p><strong>Philippians 3:10 NIV</strong></p><p>Do You Know Christ?</p><p><span class=ql-size-small>Do You Know The Power Of His Resurrection?</span></p><p><strong class=ql-size-small>Ephesians 1:19-20 LB</strong></p><p><strong class=ql-size-small>Isaiah 61:1-4 NIV</strong></p><p><span class=ql-size-small>&nbsp_Four Ways To Do This!!!!</span></p><p><span class=ql-size-small>&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_#1-Stop Dying</span></p><p><br></p><p><span class=ql-size-small>reverse the curse!!!</span></p><p><br></p><p><span class=ql-size-small>&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_�The Lord has anointed me to proclaim Good News to the poor��</span></p><p><span class=ql-size-small>&nbsp_&nbsp_#2-Start Rebuilding</span></p><p><span class=ql-size-small>&nbsp_&nbsp_�Bind up the brokenhearted�proclaim freedom for the captives�release from darkness for the prisoners��</span></p><p>There is a Path Back!!!</p><p>Grace will meet you where you are but it will never leave you where it found you.</p><p>&nbsp_His plan is to restore you to his plan!</p><p>&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_#3 - Stop Doubting</p><p>&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_&nbsp_�They will be called oaks of righteousness, a planting of the Lord for&nbsp_&nbsp_&nbsp_the display of his splendor.�</p><p>&nbsp_GOD SEES GREATNESS IN ME THAT I CAN�T SEE IN MYSELF.</p><p><span class=ql-size-small>&nbsp_#4 -Start Living</span></p><p>&nbsp_</p><p><span class=ql-size-small>&nbsp_&nbsp_�They will rebuild the ancient ruins and restore the places long devastated_ they will renew the ruined cities that have been devastated for generations.�</span></p><p><span class=ql-size-small>&nbsp_&nbsp_Jesus didn�t come to make bad people good.</span></p><p><span class=ql-size-small>&nbsp_&nbsp_He came to make dead people alive.</span></p><p>&nbsp_</p>"
  ["date"]=>
  string(10) "2018-04-01"
  ["visibility"]=>
  string(7) "private"
  ["status"]=>
  string(1) "1"
  ["created"]=>
  string(19) "2018-07-18 03:12:04"
  ["author_id"]=>
  string(1) "2"
  ["modified"]=>
  NULL
  ["edit"]=>
  string(19) "editJot.php?id=9033"
  ["copy"]=>
  string(0) ""
  ["tags"]=>
  string(0) ""
}

This is the var_dump out put of an array., The string value of ['body'] is the reason of the json encode returning false. How to fix it?

For html encoding best to use json_encode($arr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); you can also check json_encode() documentation for this also best to decode it like this json_decode($json, true)

json_encode($arr, JSON_INVALID_UTF8_SUBSTITUTE);

This will convert invalid UTF-8 characters such as � to \0xfffd (Unicode Character 'REPLACEMENT CHARACTER') Available as of PHP 7.2.0.

https://www.php.net/manual/en/json.constants.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM