{"id":625,"date":"2014-07-18T13:23:05","date_gmt":"2014-07-18T13:23:05","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=625"},"modified":"2014-07-18T13:23:05","modified_gmt":"2014-07-18T13:23:05","slug":"%e5%a6%82%e4%bd%95%e5%be%97%e5%88%b0%e4%b8%80%e4%b8%aa%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e5%90%84%e4%b8%aa%e5%ad%97%e7%ac%a6%e5%87%ba%e7%8e%b0%e7%9a%84%e6%ac%a1%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/625.html","title":{"rendered":"\u5982\u4f55\u5f97\u5230\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u5404\u4e2a\u5b57\u7b26\u51fa\u73b0\u7684\u6b21\u6570\uff1f"},"content":{"rendered":"<p>\u4eceOutOfMemory\u4e0a\u770b\u5230\u7684\u4e00\u4e2a\u9898\u76ee\uff0c\u7136\u540e\u770b\u4e86\u770b\u5176\u4e2d\u7684\u4ee3\u7801\uff0c\u7ed3\u5408\u81ea\u5df1\u4e4b\u524d\u7684\u7ecf\u9a8c\u7406\u89e3\u4e86\u4e00\u4e0b\uff0c\u89c9\u5f97\u4ee3\u7801\u4e0d\u9519\uff0c\u5c31\u653e\u4e0a\u6765\u4e86\uff1a<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\n$str=\"asdfgfdas323344##$\\$fdsdfg*$**$*$**$$443563536254fas\";\t\/\/\u4efb\u610f\u957f\u5ea6\u5b57\u7b26\u4e32\n\n\/\/\u89e3\u6cd5\u4e00(\u6700\u65b9\u4fbf\u7684\u89e3\u6cd5)\n$arr=str_split($str);\n$arr=array_count_values($arr);\narsort($arr);\nprint_r($arr);\n\n\/\/\u89e3\u6cd5\u4e8c(\u7528\u5b57\u7b26\u672c\u8eab\u4f5c\u4e3a\u6570\u7ec4\u4e0b\u6807)\n$arr=str_split($str);\n$con=array();\nforeach ($arr as $v) {\n\tif (!@$con[$v]) {\n\t\t@$con[$v]=1;\n\t} else {\n\t\t@$con[$v]++;\n\t}\n}\narsort($con);\nprint_r($con);\n\n\/\/\u89e3\u6cd5\u4e09\n$arr=str_split($str);\n$unique=array_unique($arr);\nforeach ($unique as $a){\n\t$arr2[$a]=substr_count($str, $a);\n}\narsort($arr2);\nprint_r($arr2);<\/pre>\n<p>\u6267\u884c\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p>C:&gt;php php_str_char_count.php<br \/>\nArray<br \/>\n(<br \/>\n[3] =&gt; 6<br \/>\n[*] =&gt; 6<br \/>\n[$] =&gt; 6<br \/>\n[4] =&gt; 5<br \/>\n[a] =&gt; 3<br \/>\n[5] =&gt; 3<br \/>\n[f] =&gt; 3<br \/>\n[s] =&gt; 3<br \/>\n[6] =&gt; 2<br \/>\n[2] =&gt; 2<br \/>\n[d] =&gt; 2<br \/>\n[#] =&gt; 2<br \/>\n[] =&gt; 1<br \/>\n[g] =&gt; 1<br \/>\n)<br \/>\nArray<br \/>\n(<br \/>\n[3] =&gt; 6<br \/>\n[*] =&gt; 6<br \/>\n[$] =&gt; 6<br \/>\n[4] =&gt; 5<br \/>\n[a] =&gt; 3<br \/>\n[5] =&gt; 3<br \/>\n[f] =&gt; 3<br \/>\n[s] =&gt; 3<br \/>\n[6] =&gt; 2<br \/>\n[2] =&gt; 2<br \/>\n[d] =&gt; 2<br \/>\n[#] =&gt; 2<br \/>\n[] =&gt; 1<br \/>\n[g] =&gt; 1<br \/>\n)<br \/>\nArray<br \/>\n(<br \/>\n[3] =&gt; 6<br \/>\n[*] =&gt; 6<br \/>\n[$] =&gt; 6<br \/>\n[4] =&gt; 5<br \/>\n[a] =&gt; 3<br \/>\n[5] =&gt; 3<br \/>\n[f] =&gt; 3<br \/>\n[s] =&gt; 3<br \/>\n[6] =&gt; 2<br \/>\n[2] =&gt; 2<br \/>\n[d] =&gt; 2<br \/>\n[#] =&gt; 2<br \/>\n[] =&gt; 1<br \/>\n[g] =&gt; 1<br \/>\n)<\/p>\n<p>\u4e0a\u9762\u7684\u90a3\u6bb5\u4ee3\u7801\u975e\u5e38\u7cbe\u7b80\uff0c\u4e0b\u9762\u76f8\u5f53\u4e8e\u662f\u5bf9\u5e94\u7684\u7e41\u4f53\u7248\u7684\uff1a<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\n\/\/PHP\u51e0\u4e2a\u51fd\u6570\u7684\u4f7f\u7528\nfunction countStr($str){\n    $str_array=str_split($str);\n    $str_array=array_count_values($str_array);\n    arsort($str_array);\n    return $str_array;\n}\n$str=\"asdfgfdas323344##$\\$fdsdfg*$**$*$**$$443563536254fas\";\nprint_r(countStr($str));\n\n\n\/\/\u7528\u5b57\u7b26\u7684\u503c\u4f5c\u4e3a\u6570\u7ec4\u4e0b\u6807\u8fdb\u884c\u7edf\u8ba1\nfunction countStr2($str){\n    $str_array=str_split($str);\n    $result_array=array();\n    foreach($str_array as $value){\/\/\u6839\u636e\u5b57\u7b26\u4e4b\u524d\u662f\u5426\u51fa\u73b0\u8fc7\u6765\u8d4b\u503c\uff0c\u6ca1\u6709\u51fa\u73b0\u8bbe\u7f6e\u4e3a1\uff0c\u5426\u5219\u5c31\u81ea\u52a01\n        if(!$result_array[$value]){\n            $result_array[$value]=1;\n        }else{\n            $result_array[$value]++;\n        }\n    }\n    arsort($result_array);\n    return $result_array;\n}\n$str=\"asdfgfdas323344##$\\$fdsdfg*$**$*$**$$443563536254fas\";\nvar_dump(countStr2($str));\n\n\n\/\/\u8fd9\u4e2a\u65b9\u6cd5\u7eaf\u7cb9\u662f\u89e3\u6cd5\u4e00\u7684\u8e69\u811a\u7248\u672c\uff0c\u5148\u627e\u51fa\u6240\u6709\u5b57\u7b26\u7684\u603b\u7c7b(array_unique)\uff0c\u7136\u540e\u518d\u4e00\u4e2a\u4e00\u4e2a\u7528substr_count\u51fd\u6570\u7edf\u8ba1\nfunction countStr3($str){\n\t$str_array=str_split($str);\n\t$unique=array_unique($str_array);\n\t$result_array=array();\n\tforeach ($unique as $v){\n\t\t$result_array[$v]=substr_count($str,$v);\n\t}\n\tarsort($result_array);\n\treturn $result_array;\n}\n$str=\"asdfgfdas323344##$\\$fdsdfg*$**$*$**$$443563536254fas\";\nvar_dump(countStr3($str));\n?&gt;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eceOutOfMemory\u4e0a\u770b\u5230\u7684\u4e00\u4e2a\u9898\u76ee\uff0c\u7136\u540e\u770b\u4e86\u770b\u5176\u4e2d\u7684\u4ee3\u7801\uff0c\u7ed3\u5408\u81ea\u5df1\u4e4b\u524d\u7684\u7ecf\u9a8c\u7406\u89e3\u4e86\u4e00\u4e0b\uff0c\u89c9\u5f97\u4ee3\u7801\u4e0d\u9519\uff0c\u5c31 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[240,241,48,242],"class_list":["post-625","post","type-post","status-publish","format-standard","hentry","category-programing","tag-array_count_values","tag-arsort","tag-php","tag-substr_count"],"views":2044,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=625"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/625\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}