$tem = $arr['invoice_type'];
echo "
"; <br> print_r($tem); <br> 输出 <br> a:2:{s:4:"type";a:3:{i:0;s:8:"个人发票";i:1;s:8:"企业发票";i:2;s:0:"";}s:4:"rate";a:3:{i:0;d:6;i:1;d:6;i:2;d:0;}} <br> <br> $teem []= preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $arr['invoice_type'] ); <br> echo "<pre class="brush:php;toolbar:false">"; <br> print_r($teem); <br> 输出 <br> Array <br> ( <br> [0] => a:2:{'s:'.strlen('type').':"type";'a:3:{i:0;'s:'.strlen('个人发票').':"个人发票";'i:1;'s:'.strlen('企业发票').':"企业发票";'i:2;'s:'.strlen('').':"";'}'s:'.strlen('rate').':"rate";'a:3:{i:0;d:6;i:1;d:6;i:2;d:0;}} <br> ) <br> <br> $teemm []= preg_replace_callback('!s:(\d+):"(.*?)";!s', function ($matches) {return strlen('$2').':\"$2\";';}, $arr['invoice_type'] ); <br> echo "<pre class="brush:php;toolbar:false">"; <br> print_r($teemm); <br> 输出 <br> Array <br> ( <br> [0] => a:2:{2:\"$2\";a:3:{i:0;2:\"$2\";i:1;2:\"$2\";i:2;2:\"$2\";}2:\"$2\";a:3:{i:0;d:6;i:1;d:6;i:2;d:0;}} <br> ) <br> <br> 如何让preg_replace_callback输出的信息和preg_replace输出的一样 <p> </p> <br> <h2 id="回复讨论-解决方案">回复讨论(解决方案)</h2> <p class="sougouAnswer"> 不知道你要干什么 <br> 实例的结果并不对! </p> <p class="sougouAnswer"> 第二个输出弄错了是下面的 <br> $teem []= preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $arr['invoice_type'] ); <br> echo "</p><pre class="brush:php;toolbar:false">"; <br> print_r($teem); <br> 输出 <br> Array <br> ( <br> [0] => a:2:{s:4:"type";a:3:{i:0;s:8:"个人发票";i:1;s:8:"企业发票";i:2;s:0:"";}s:4:"rate";a:3:{i:0;d:6;i:1;d:6;i:2;d:0;}} <br> ) <p class="sougouAnswer"> </p><p class="yy"> 不知道你要干什么 <br> 实例的结果并不对! </p> <br> <br> 第二个输出弄错了是下面的 <br> $teem []= preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $arr['invoice_type'] ); <br> echo "<pre class="brush:php;toolbar:false">"; <br> print_r($teem); <br> 输出 <br> Array <br> ( <br> [0] => a:2:{s:4:"type";a:3:{i:0;s:8:"个人发票";i:1;s:8:"企业发票";i:2;s:0:"";}s:4:"rate";a:3:{i:0;d:6;i:1;d:6;i:2;d:0;}} <br> ) <p class="sougouAnswer"> <pre class='brush:php;toolbar:false;'>$s = preg_replace_callback('/s:\d+:"(.+?)";/s', function($r) { $n = strlen($r[1]); return "s:$n:\"$r[1]\";"; }, $s);
$s = preg_replace_callback('/s:\d+:"(.+?)";/s', function($r) { $n = strlen($r[1]); return "s:$n:\"$r[1]\";"; }, $s);
大神我按照你的改了输出数据是这样
代码
$teem = preg_replace_callback('/s:\d+:"(.+?)";/s',
function($r) {
$n = strlen($r[1]);
return "s:$n:\"$r[1]\";";
}, $arr['invoice_type'] );
echo "
"; <br> print_r($teem); <br> 输出 <br> a:2:{s:4:"type";a:3:{i:0;s:8:"个人发票";i:1;s:8:"企业发票";i:2;s:12:"";}s:4:"rate";a:3:{i:0;d:6;i:1;d:6;i:2;d:0;}} <br> <br> 企业发票后边S:0:"" 变为了s:12:"" 多了12长度,这个怎么来的 <br> <p class="sougouAnswer"> 没考虑值为空的情况 <br> 把 '/s:\d+:"(.+?)";/s' <br> 改为 '/s:\d+:"(.*?)";/s' </p> <p class="sougouAnswer"> </p><p class="yy"> 没考虑值为空的情况 <br> 把 '/s:\d+:"(.+?)";/s' <br> 改为 '/s:\d+:"(.*?)";/s' </p> <br> <br> 万分感谢

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

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


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

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
