Remember how to process the json string composed of a large number of html and svg in the database into an array

I use tp6.0 

First of all, I thought of using the json_decode that comes with the framework to decode the string in JSON format, but found that it didn’t work.

json_decode(
    string $json,
    ?bool $associative = null,
    int $depth = 512,
    int $flags = 0
): mixed

The json function can only handle UTF-8 encoded data.

associative

When true true  , the JSON object will return the associative array; when false true, the JSON object will return object. When null true  , the JSON object will return an associative array or object, depending on whether it flags is set in  JSON_OBJECT_AS_ARRAY.

depth

The structure that needs to be decoded, its maximum nesting depth. The value must be greater than  0 or less than or equal to  2147483647.

flags

 A mask consisting of  JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY,JSON_THROW_ON_ERROR

html_entity_decode() is the opposite  of  htmlentities()  in that it converts HTML entities in the corresponding characters.

More precisely, this function decodes all entities (including all numeric entities) that a) must be valid for the selected document type—that is, for XML, this function does not decode named entities that may be defined in some DTDs—and b ) whose character or set of characters in an encoded character is associated with the selected encoding and allows the document type in the selected encoding. All other entities remain as-is

stripslashes()

Dequotes a quoted string.

If you don't need to insert data into a location that needs to be escaped (such as a database), you can use  stripslashes()

$str="[{"answer":"<p>&nbsp;<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"5.418ex\\" height=\\"1.563ex\\" role=\\"img\\" focusable=\\"false\\" viewBox=\\"0 -669 2394.7 691\\" xmlns:xlink=\\"http://www.w3.org/1999/xlink\\" aria-hidden=\\"true\\" style=\\"vertical-align: -0.05ex;\\"><defs><path id=\\"MJX-1-TEX-N-73\\" d=\\"M295 316Q295 356 268 385T190 414Q154 414 128 401Q98 382 98 349Q97 344 98 336T114 312T157 287Q175 282 201 278T245 269T277 256Q294 248 310 236T342 195T359 133Q359 71 321 31T198 -10H190Q138 -10 94 26L86 19L77 10Q71 4 65 -1L54 -11H46H42Q39 -11 33 -5V74V132Q33 153 35 157T45 162H54Q66 162 70 158T75 146T82 119T101 77Q136 26 198 26Q295 26 295 104Q295 133 277 151Q257 175 194 187T111 210Q75 227 54 256T33 318Q33 357 50 384T93 424T143 442T187 447H198Q238 447 268 432L283 424L292 431Q302 440 314 448H322H326Q329 448 335 442V310L329 304H301Q295 310 295 316Z\\"></path><path id=\\"MJX-1-TEX-N-69\\" d=\\"M69 609Q69 637 87 653T131 669Q154 667 171 652T188 609Q188 579 171 564T129 549Q104 549 87 564T69 609ZM247 0Q232 3 143 3Q132 3 106 3T56 1L34 0H26V46H42Q70 46 91 49Q100 53 102 60T104 102V205V293Q104 345 102 359T88 378Q74 385 41 385H30V408Q30 431 32 431L42 432Q52 433 70 434T106 436Q123 437 142 438T171 441T182 442H185V62Q190 52 197 50T232 46H255V0H247Z\\"></path><path id=\\"MJX-1-TEX-N-6E\\" d=\\"M41 46H55Q94 46 102 60V68Q102 77 102 91T102 122T103 161T103 203Q103 234 103 269T102 328V351Q99 370 88 376T43 385H25V408Q25 431 27 431L37 432Q47 433 65 434T102 436Q119 437 138 438T167 441T178 442H181V402Q181 364 182 364T187 369T199 384T218 402T247 421T285 437Q305 442 336 442Q450 438 463 329Q464 322 464 190V104Q464 66 466 59T477 49Q498 46 526 46H542V0H534L510 1Q487 2 460 2T422 3Q319 3 310 0H302V46H318Q379 46 379 62Q380 64 380 200Q379 335 378 343Q372 371 358 385T334 402T308 404Q263 404 229 370Q202 343 195 315T187 232V168V108Q187 78 188 68T191 55T200 49Q221 46 249 46H265V0H257L234 1Q210 2 183 2T145 3Q42 3 33 0H25V46H41Z\\"></path><path id=\\"MJX-1-TEX-N-2061\\" d=\\"\\"></path><path id=\\"MJX-1-TEX-N-36\\" d=\\"M42 313Q42 476 123 571T303 666Q372 666 402 630T432 550Q432 525 418 510T379 495Q356 495 341 509T326 548Q326 592 373 601Q351 623 311 626Q240 626 194 566Q147 500 147 364L148 360Q153 366 156 373Q197 433 263 433H267Q313 433 348 414Q372 400 396 374T435 317Q456 268 456 210V192Q456 169 451 149Q440 90 387 34T253 -22Q225 -22 199 -14T143 16T92 75T56 172T42 313ZM257 397Q227 397 205 380T171 335T154 278T148 216Q148 133 160 97T198 39Q222 21 251 21Q302 21 329 59Q342 77 347 104T352 209Q352 289 347 316T329 361Q302 397 257 397Z\\"></path><path id=\\"MJX-1-TEX-N-30\\" d=\\"M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z\\"></path></defs><g stroke=\\"currentColor\\" fill=\\"currentColor\\" stroke-width=\\"0\\" transform=\\"scale(1,-1)\\"><g data-mml-node=\\"math\\"><g data-mml-node=\\"mi\\"><use data-c=\\"73\\" xlink:href=\\"#MJX-1-TEX-N-73\\"></use><use data-c=\\"69\\" xlink:href=\\"#MJX-1-TEX-N-69\\" transform=\\"translate(394,0)\\"></use><use data-c=\\"6E\\" xlink:href=\\"#MJX-1-TEX-N-6E\\" transform=\\"translate(672,0)\\"></use></g><g data-mml-node=\\"mo\\" transform=\\"translate(1228,0)\\"><use data-c=\\"2061\\" xlink:href=\\"#MJX-1-TEX-N-2061\\"></use></g><g data-mml-node=\\"TeXAtom\\" data-mjx-texclass=\\"ORD\\" transform=\\"translate(1394.7,0)\\"><g data-mml-node=\\"mn\\"><use data-c=\\"36\\" xlink:href=\\"#MJX-1-TEX-N-36\\"></use><use data-c=\\"30\\" xlink:href=\\"#MJX-1-TEX-N-30\\" transform=\\"translate(500,0)\\"></use></g></g></g></g></svg>&nbsp;<br/></p>","review":0,"score":123,"deserve":0,"topicid":551},{"answer":"A","review":0,"score":12,"deserve":0,"topicid":560},{"answer":"<p>&nbsp;<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"4.651ex\\" height=\\"3.257ex\\" role=\\"img\\" focusable=\\"false\\" viewBox=\\"0 -694 2055.7 1439.7\\" xmlns:xlink=\\"http://www.w3.org/1999/xlink\\" aria-hidden=\\"true\\" style=\\"vertical-align: -1.687ex;\\"><defs><path id=\\"MJX-2-TEX-N-6C\\" d=\\"M42 46H56Q95 46 103 60V68Q103 77 103 91T103 124T104 167T104 217T104 272T104 329Q104 366 104 407T104 482T104 542T103 586T103 603Q100 622 89 628T44 637H26V660Q26 683 28 683L38 684Q48 685 67 686T104 688Q121 689 141 690T171 693T182 694H185V379Q185 62 186 60Q190 52 198 49Q219 46 247 46H263V0H255L232 1Q209 2 183 2T145 3T107 3T57 1L34 0H26V46H42Z\\"></path><path id=\\"MJX-2-TEX-N-69\\" d=\\"M69 609Q69 637 87 653T131 669Q154 667 171 652T188 609Q188 579 171 564T129 549Q104 549 87 564T69 609ZM247 0Q232 3 143 3Q132 3 106 3T56 1L34 0H26V46H42Q70 46 91 49Q100 53 102 60T104 102V205V293Q104 345 102 359T88 378Q74 385 41 385H30V408Q30 431 32 431L42 432Q52 433 70 434T106 436Q123 437 142 438T171 441T182 442H185V62Q190 52 197 50T232 46H255V0H247Z\\"></path><path id=\\"MJX-2-TEX-N-6D\\" d=\\"M41 46H55Q94 46 102 60V68Q102 77 102 91T102 122T103 161T103 203Q103 234 103 269T102 328V351Q99 370 88 376T43 385H25V408Q25 431 27 431L37 432Q47 433 65 434T102 436Q119 437 138 438T167 441T178 442H181V402Q181 364 182 364T187 369T199 384T218 402T247 421T285 437Q305 442 336 442Q351 442 364 440T387 434T406 426T421 417T432 406T441 395T448 384T452 374T455 366L457 361L460 365Q463 369 466 373T475 384T488 397T503 410T523 422T546 432T572 439T603 442Q729 442 740 329Q741 322 741 190V104Q741 66 743 59T754 49Q775 46 803 46H819V0H811L788 1Q764 2 737 2T699 3Q596 3 587 0H579V46H595Q656 46 656 62Q657 64 657 200Q656 335 655 343Q649 371 635 385T611 402T585 404Q540 404 506 370Q479 343 472 315T464 232V168V108Q464 78 465 68T468 55T477 49Q498 46 526 46H542V0H534L510 1Q487 2 460 2T422 3Q319 3 310 0H302V46H318Q379 46 379 62Q380 64 380 200Q379 335 378 343Q372 371 358 385T334 402T308 404Q263 404 229 370Q202 343 195 315T187 232V168V108Q187 78 188 68T191 55T200 49Q221 46 249 46H265V0H257L234 1Q210 2 183 2T145 3Q42 3 33 0H25V46H41Z\\"></path><path id=\\"MJX-2-TEX-N-34\\" d=\\"M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z\\"></path><path id=\\"MJX-2-TEX-N-33\\" d=\\"M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z\\"></path></defs><g stroke=\\"currentColor\\" fill=\\"currentColor\\" stroke-width=\\"0\\" transform=\\"scale(1,-1)\\"><g data-mml-node=\\"math\\"><g data-mml-node=\\"munder\\"><g data-mml-node=\\"mo\\"><use data-c=\\"6C\\" xlink:href=\\"#MJX-2-TEX-N-6C\\"></use><use data-c=\\"69\\" xlink:href=\\"#MJX-2-TEX-N-69\\" transform=\\"translate(278,0)\\"></use><use data-c=\\"6D\\" xlink:href=\\"#MJX-2-TEX-N-6D\\" transform=\\"translate(556,0)\\"></use></g><g data-mml-node=\\"TeXAtom\\" transform=\\"translate(517.7,-645.7) scale(0.707)\\" data-mjx-texclass=\\"ORD\\"><g data-mml-node=\\"mn\\"><use data-c=\\"34\\" xlink:href=\\"#MJX-2-TEX-N-34\\"></use></g></g></g><g data-mml-node=\\"TeXAtom\\" data-mjx-texclass=\\"ORD\\" transform=\\"translate(1555.7,0)\\"><g data-mml-node=\\"mn\\"><use data-c=\\"33\\" xlink:href=\\"#MJX-2-TEX-N-33\\"></use></g></g></g></g></svg>&nbsp;<br/></p>","review":0,"score":50,"deserve":0,"topicid":561},{"answer":"A,B","review":0,"score":1,"deserve":0,"topicid":565},{"answer":"A,C","review":0,"score":2,"deserve":0,"topicid":566},{"answer":"B","review":0,"score":2,"deserve":0,"topicid":567},{"answer":"<p>&nbsp;<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"7.133ex\\" height=\\"5.555ex\\" role=\\"img\\" focusable=\\"false\\" viewBox=\\"0 -1559 3152.6 2455.3\\" xmlns:xlink=\\"http://www.w3.org/1999/xlink\\" aria-hidden=\\"true\\" style=\\"vertical-align: -2.028ex;\\"><defs><path id=\\"MJX-3-TEX-LO-222D\\" d=\\"M114 -798Q132 -824 165 -824H167Q195 -824 223 -764T275 -600T320 -391T362 -164Q365 -143 367 -133Q439 292 523 655T645 1127Q651 1145 655 1157T672 1201T699 1257T733 1306T777 1346T828 1360Q884 1360 912 1325T944 1245Q944 1220 932 1205T909 1186T887 1183Q866 1183 849 1198T832 1239Q832 1287 885 1296L882 1300Q879 1303 874 1307T866 1313Q851 1323 833 1323Q819 1323 807 1311T775 1255T736 1139T689 936T633 628Q574 293 510 -5T410 -437T355 -629Q278 -862 165 -862Q125 -862 92 -831T55 -746Q55 -711 74 -698T112 -685Q133 -685 150 -700T167 -741Q167 -789 114 -798ZM642 -798Q660 -824 693 -824H695Q723 -824 751 -764T803 -600T848 -391T890 -164Q893 -143 895 -133Q967 292 1051 655T1173 1127Q1179 1145 1183 1157T1200 1201T1227 1257T1261 1306T1305 1346T1356 1360Q1412 1360 1440 1325T1472 1245Q1472 1220 1460 1205T1437 1186T1415 1183Q1394 1183 1377 1198T1360 1239Q1360 1287 1413 1296L1410 1300Q1407 1303 1402 1307T1394 1313Q1379 1323 1361 1323Q1347 1323 1335 1311T1303 1255T1264 1139T1217 936T1161 628Q1102 293 1038 -5T938 -437T883 -629Q806 -862 693 -862Q653 -862 620 -831T583 -746Q583 -711 602 -698T640 -685Q661 -685 678 -700T695 -741Q695 -789 642 -798ZM1150 -798Q1168 -824 1201 -824H1203Q1231 -824 1259 -764T1311 -600T1356 -391T1398 -164Q1401 -143 1403 -133Q1475 292 1559 655T1681 1127Q1687 1145 1691 1157T1708 1201T1735 1257T1769 1306T1813 1346T1864 1360Q1920 1360 1948 1325T1980 1245Q1980 1220 1968 1205T1945 1186T1923 1183Q1902 1183 1885 1198T1868 1239Q1868 1287 1921 1296L1918 1300Q1915 1303 1910 1307T1902 1313Q1887 1323 1869 1323Q1855 1323 1843 1311T1811 1255T1772 1139T1725 936T1669 628Q1610 293 1546 -5T1446 -437T1391 -629Q1314 -862 1201 -862Q1161 -862 1128 -831T1091 -746Q1091 -711 1110 -698T1148 -685Q1169 -685 1186 -700T1203 -741Q1203 -789 1150 -798Z\\"></path><path id=\\"MJX-3-TEX-N-32\\" d=\\"M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z\\"></path><path id=\\"MJX-3-TEX-N-33\\" d=\\"M127 463Q100 463 85 480T69 524Q69 579 117 622T233 665Q268 665 277 664Q351 652 390 611T430 522Q430 470 396 421T302 350L299 348Q299 347 308 345T337 336T375 315Q457 262 457 175Q457 96 395 37T238 -22Q158 -22 100 21T42 130Q42 158 60 175T105 193Q133 193 151 175T169 130Q169 119 166 110T159 94T148 82T136 74T126 70T118 67L114 66Q165 21 238 21Q293 21 321 74Q338 107 338 175V195Q338 290 274 322Q259 328 213 329L171 330L168 332Q166 335 166 348Q166 366 174 366Q202 366 232 371Q266 376 294 413T322 525V533Q322 590 287 612Q265 626 240 626Q208 626 181 615T143 592T132 580H135Q138 579 143 578T153 573T165 566T175 555T183 540T186 520Q186 498 172 481T127 463Z\\"></path></defs><g stroke=\\"currentColor\\" fill=\\"currentColor\\" stroke-width=\\"0\\" transform=\\"scale(1,-1)\\"><g data-mml-node=\\"math\\"><g data-mml-node=\\"msubsup\\"><g data-mml-node=\\"mo\\" transform=\\"translate(0 1)\\"><use data-c=\\"222D\\" xlink:href=\\"#MJX-3-TEX-LO-222D\\"></use></g><g data-mml-node=\\"TeXAtom\\" transform=\\"translate(2082.4,1088.1) scale(0.707)\\" data-mjx-texclass=\\"ORD\\"><g data-mml-node=\\"mn\\"><use data-c=\\"32\\" xlink:href=\\"#MJX-3-TEX-N-32\\"></use></g></g><g data-mml-node=\\"TeXAtom\\" transform=\\"translate(1625,-896.4) scale(0.707)\\" data-mjx-texclass=\\"ORD\\"><g data-mml-node=\\"mn\\"><use data-c=\\"32\\" xlink:href=\\"#MJX-3-TEX-N-32\\"></use></g></g></g><g data-mml-node=\\"TeXAtom\\" data-mjx-texclass=\\"ORD\\" transform=\\"translate(2652.6,0)\\"><g data-mml-node=\\"mn\\"><use data-c=\\"33\\" xlink:href=\\"#MJX-3-TEX-N-33\\"></use></g></g></g></g></svg>&nbsp;<br/></p>","review":0,"score":1,"deserve":0,"topicid":569},{"answer":"<p>不知道111</p>","review":0,"score":3,"deserve":0,"topicid":570},{"answer":"<p>不知道22</p>","review":0,"score":2,"deserve":0,"topicid":571},{"answer":"A","review":0,"score":2,"deserve":0,"topicid":572},{"answer":"<p>&nbsp;<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"2.891ex\\" height=\\"2.262ex\\" role=\\"img\\" focusable=\\"false\\" viewBox=\\"0 -750 1278 1000\\" xmlns:xlink=\\"http://www.w3.org/1999/xlink\\" aria-hidden=\\"true\\" style=\\"vertical-align: -0.566ex;\\"><defs><path id=\\"MJX-4-TEX-N-28\\" d=\\"M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z\\"></path><path id=\\"MJX-4-TEX-N-32\\" d=\\"M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z\\"></path><path id=\\"MJX-4-TEX-N-29\\" d=\\"M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z\\"></path></defs><g stroke=\\"currentColor\\" fill=\\"currentColor\\" stroke-width=\\"0\\" transform=\\"scale(1,-1)\\"><g data-mml-node=\\"math\\"><g data-mml-node=\\"mrow\\"><g data-mml-node=\\"mo\\"><use data-c=\\"28\\" xlink:href=\\"#MJX-4-TEX-N-28\\"></use></g><g data-mml-node=\\"TeXAtom\\" data-mjx-texclass=\\"ORD\\" transform=\\"translate(389,0)\\"><g data-mml-node=\\"mn\\"><use data-c=\\"32\\" xlink:href=\\"#MJX-4-TEX-N-32\\"></use></g></g><g data-mml-node=\\"mo\\" transform=\\"translate(889,0)\\"><use data-c=\\"29\\" xlink:href=\\"#MJX-4-TEX-N-29\\"></use></g></g></g></g></svg>&nbsp;<br/></p>","review":0,"score":10,"deserve":0,"topicid":573},{"answer":"A","review":0,"score":3,"deserve":0,"topicid":574},{"answer":"A","review":0,"score":1,"deserve":0,"topicid":672},{"answer":"C","review":0,"score":3,"deserve":0,"topicid":673},{"answer":"D","review":0,"score":1,"deserve":0,"topicid":674},{"answer":"D","review":0,"score":3,"deserve":0,"topicid":675},{"answer":"D","review":0,"score":2,"deserve":0,"topicid":676},{"answer":"<p>不知道00</p>","review":0,"score":1,"deserve":0,"topicid":677}]";

$a= stripslashes(html_entity_decode($str));
$b= json_decode($a, true);
After these three functions, $b is an array we are familiar with

Guess you like

Origin blog.csdn.net/qq_58778333/article/details/130286399
Recommended