php 数组转换字符串函数, 我用thinkphp ,json_encode保存中文,反斜杠消失了
原本是这个
[{"title":"\u5173\u6ce8\u65f6\u56de\u590d","url":"\/index.php?g=User****"}]
结果变成这个了
[{"title":"u5173u6ce8u65f6u56deu590d","url":"\/index.php?g=User****"}]
就是中文,用json_decode 处理,保存到数据库就没有反斜杠了,
php版本 5.2, apache 2.2
我记得有一个可以保存变量类型 的, 数组转换字符串, 忘记叫什么了
回复讨论(解决方案)
散分了
serialize($array);
unserialize($array);
有惊喜, 找到了
是Thinkphp的问题?
直接用php的json_encode不会没有反斜杠的。
echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';$arr = array( array( 'title' => '关注时回复', 'url' => '/index.php?g=User****' ));$str = json_encode($arr); //echo $str.'<br>';echo '<pre class="brush:php;toolbar:false">';print_r(json_decode($str,true));echo '';
[{"title":"\u5173\u6ce8\u65f6\u56de\u590d","url":"\/index.php?g=User****"}]
Array
(
[0] => Array
(
[title] => 关注时回复
[url] => /index.php?g=User****
)
)
应该是环境的原因,斜杠被处理掉。
你看下有没有对数据进行 stripslashes 之类的处理,在保存到数据库之前
接分了 恭喜楼主
你看下有没有对数据进行 stripslashes 之类的处理,在保存到数据库之前
不清楚,应该是处理了,
请问在哪里设置?
我用 json_decode 有反斜杠, 保存到数据库就没有 了,
还要本地没事,上传服务器就不行了, 配置一样
本地php 5.5
服务器php 5.2的,
用 serialize 这个函数代替了,
返回字符串, 数组 变量类型都会保存,不变
是Thinkphp的问题?
直接用php的json_encode不会没有反斜杠的。
echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';$arr = array( array( 'title' => '关注时回复', 'url' => '/index.php?g=User****' ));$str = json_encode($arr); //echo $str.'<br>';echo '<pre class="brush:php;toolbar:false">';print_r(json_decode($str,true));echo '';
[{"title":"\u5173\u6ce8\u65f6\u56de\u590d","url":"\/index.php?g=User****"}]
Array
(
[0] => Array
(
[title] => 关注时回复
[url] => /index.php?g=User****
)
)
感觉是thinkphp 的问题, 保存之后就没有了, $db->save(json);
接点分用用
save 是保存到数据库,那么你的 "\u5173\u6ce8\u65f6\u56de\u590d" 中的 \ 不需要转义吗?TP 会替你做?
save 是保存到数据库,那么你的 "\u5173\u6ce8\u65f6\u56de\u590d" 中的 \ 不需要转义吗?TP 会替你做?
明白了 , 需要 这个是吗?
str_replace("/\\/","\\\\",json)
是不是写入数据库都需要转义?
是的,写入数据库的时候要转义特殊字符
是的,写入数据库的时候要转义特殊字符
恩 ,谢谢, 以前 用asp 的, 只有是变量里面的值 都不用管, 就可以写入数据库 ,知道了
谢谢 结贴了
,json_encode(array()) ;//写入数据库反斜杠消失, 需要转义
asp 中 \ 不是特殊字符,但 ' 还是要转义的

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
