


How php simulates users to automatically publish articles in qq space
What we have here is a simple program that uses PHP to simulate logging in and then sending articles to QQ space. Friends in need can refer to it.
<ol class="dp-c"><li class="alt"><span><span><?php </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//模拟get post请求函数 http://www.lai18.com</span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">/* </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">函数说明: </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">功能:请求方式可以get,post,可以发送的cookie,保存的cookiefile文件 </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">参数:$url-----请求url $referer---来源url $postdata----------用于post请求的数据,''为get请求 </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">$cookie---------发送的cookie $cookiefile-----保存的cookiefile文件 </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">返回值:返回获取的源码 </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">*/</span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">function</span><span> request(</span><span class="vars">$url</span><span>,</span><span class="vars">$referer</span><span>=</span><span class="string">''</span><span>,</span><span class="vars">$postdata</span><span>=</span><span class="string">''</span><span>,</span><span class="vars">$cookie</span><span>=</span><span class="string">''</span><span>,</span><span class="vars">$cookiefile</span><span>=</span><span class="string">''</span><span>){ </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//header设置 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$header</span><span>=</span><span class="string">''</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$header</span><span>.=</span><span class="string">"Content-Type: application/x-www-form-urlencodedrn"</span><span>;</span><span class="comment">//内容请求类型 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$header</span><span>.=</span><span class="string">"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)rn"</span><span>;</span><span class="comment">//浏览器字段 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$header</span><span>.=</span><span class="string">"Referer:"</span><span>.</span><span class="vars">$referer</span><span>.</span><span class="string">"rn"</span><span>;</span><span class="comment">//设置来源地址 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$header</span><span> .= </span><span class="string">"Cookie:"</span><span>.</span><span class="vars">$cookie</span><span> ; </span><span class="comment">//设置cookie,默认空 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//请求方法get post,通过$postdata空---get,非空----post </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">if</span><span>(</span><span class="vars">$postdata</span><span>==</span><span class="string">''</span><span>)</span><span class="vars">$method</span><span>=</span><span class="string">'GET'</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">else</span><span> </span><span class="vars">$method</span><span>=</span><span class="string">'POST'</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//定义用于创建流的数组 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$opts</span><span>=</span><span class="keyword">array</span><span>(); </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$opts</span><span>[</span><span class="string">'http'</span><span>]=</span><span class="keyword">array</span><span>(</span><span class="string">'method'</span><span>=></span><span class="vars">$method</span><span>,</span><span class="string">'header'</span><span>=></span><span class="vars">$header</span><span>,</span><span class="string">'content'</span><span>=></span><span class="vars">$postdata</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//生成流 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$context</span><span>=stream_context_create(</span><span class="vars">$opts</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//发送请求,获取源码 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$yuanma</span><span>=</span><span class="func">file_get_contents</span><span>(</span><span class="vars">$url</span><span>,false,</span><span class="vars">$context</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//是否需要保存cookie到文件,$cookiefile不空时 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">if</span><span>(</span><span class="vars">$cookiefile</span><span>!=</span><span class="string">''</span><span>){ </span></span></li><li><span> </span></li><li class="alt"><span><span class="func">echo</span><span> </span><span class="string">'需要保存cookie<br>'</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//判断保存文件存在,不存在创建 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">if</span><span>(!</span><span class="func">file_exists</span><span>(</span><span class="vars">$cookiefile</span><span>)){ </span></span></li><li><span> </span></li><li class="alt"><span><span class="func">file_put_contents</span><span>(</span><span class="vars">$cookiefile</span><span>,</span><span class="string">''</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span>} </span></li><li><span> </span></li><li class="alt"><span><span class="comment">//获取cookie,保存起来 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$response</span><span>=implode(</span><span class="string">"rn"</span><span>,</span><span class="vars">$http_response_header</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//用正则匹配cookie </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$zengze</span><span>=</span><span class="string">"/Set-Cookie:(.*?)rn/"</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span>preg_match_all(<span class="vars">$zengze</span><span>,</span><span class="vars">$response</span><span>,</span><span class="vars">$cookie_arr</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//存在匹配,保存 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">if</span><span>(!emptyempty(</span><span class="vars">$cookie_arr</span><span>[1])){ </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$cookiestr</span><span>=implode(</span><span class="string">';'</span><span>,</span><span class="vars">$cookie_arr</span><span>[1]); </span></span></li><li><span> </span></li><li class="alt"><span><span class="func">file_put_contents</span><span>(</span><span class="vars">$cookiefile</span><span>,</span><span class="vars">$cookiestr</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span><span class="func">echo</span><span> </span><span class="string">'成功保存cookie<br>'</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span>} </span></li><li><span> </span></li><li class="alt"><span><span class="keyword">else</span><span> </span><span class="func">echo</span><span> </span><span class="string">'没有匹配到cookie<br>'</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span>}<span class="comment">//end if($cookiefile!='') </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//返回源码 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">return</span><span> </span><span class="vars">$yuanma</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span>}<span class="comment">//end function request($url,$referer,$postdata,$cookie,$cookiefile) </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//获得当前的脚本网址 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">function</span><span> GetCurUrl() </span></span></li><li><span> </span></li><li class="alt"><span>{ </span></li><li><span> </span></li><li class="alt"><span><span class="keyword">if</span><span>(!emptyempty(</span><span class="vars">$_SERVER</span><span>[</span><span class="string">"REQUEST_URI"</span><span>])) </span></span></li><li><span> </span></li><li class="alt"><span>{ </span></li><li><span> </span></li><li class="alt"><span><span class="vars">$scriptName</span><span> = </span><span class="vars">$_SERVER</span><span>[</span><span class="string">"REQUEST_URI"</span><span>]; </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$nowurl</span><span> = </span><span class="vars">$scriptName</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span>} </span></li><li><span> </span></li><li class="alt"><span><span class="keyword">else</span><span> </span></span></li><li><span> </span></li><li class="alt"><span>{ </span></li><li><span> </span></li><li class="alt"><span><span class="vars">$scriptName</span><span> = </span><span class="vars">$_SERVER</span><span>[</span><span class="string">"PHP_SELF"</span><span>]; </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">if</span><span>(emptyempty(</span><span class="vars">$_SERVER</span><span>[</span><span class="string">"QUERY_STRING"</span><span>])) </span></span></li><li><span> </span></li><li class="alt"><span>{ </span></li><li><span> </span></li><li class="alt"><span><span class="vars">$nowurl</span><span> = </span><span class="vars">$scriptName</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span>} </span></li><li><span> </span></li><li class="alt"><span><span class="keyword">else</span><span> </span></span></li><li><span> </span></li><li class="alt"><span>{ </span></li><li><span> </span></li><li class="alt"><span><span class="vars">$nowurl</span><span> = </span><span class="vars">$scriptName</span><span>.</span><span class="string">"?"</span><span>.</span><span class="vars">$_SERVER</span><span>[</span><span class="string">"QUERY_STRING"</span><span>]; </span></span></li><li><span> </span></li><li class="alt"><span>} </span></li><li><span> </span></li><li class="alt"><span>} </span></li><li><span> </span></li><li class="alt"><span><span class="keyword">return</span><span> </span><span class="vars">$nowurl</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span>} </span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span><span class="comment">//获得当前文件名 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$nowurl</span><span>=GetCurUrl(); </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//echo $nowurl; </span><span> </span></span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span><span class="comment">//表单输出,没有提交时 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">if</span><span>(!isset(</span><span class="vars">$_POST</span><span>[</span><span class="string">'qq'</span><span>])){ </span></span></li><li><span> </span></li><li class="alt"><span><span class="func">echo</span><span> </span><span class="string">'<form method="post" action="'</span><span>.</span><span class="vars">$nowurl</span><span>.'"> </span></span></li><li><span> </span></li><li class="alt"><span>qq号码:<input type=<span class="string">"text"</span><span> name=</span><span class="string">"qq"</span><span>><br> </span></span></li><li><span> </span></li><li class="alt"><span>g_tk:<input type=<span class="string">"text"</span><span> name=</span><span class="string">"g_tk"</span><span>><br> </span></span></li><li><span> </span></li><li class="alt"><span>标题:<input type=<span class="string">"text"</span><span> name=</span><span class="string">"title"</span><span>><br> </span></span></li><li><span> </span></li><li class="alt"><span>内容:<input type=<span class="string">"text"</span><span> name=</span><span class="string">"content"</span><span>><br> </span></span></li><li><span> </span></li><li class="alt"><span><input type=<span class="string">"submit"</span><span> value=</span><span class="string">"发表文章"</span><span>> </span></span></li><li><span> </span></li><li class="alt"><span></form>'; </span></li><li><span> </span></li><li class="alt"><span><span class="keyword">die</span><span>(); </span></span></li><li><span> </span></li><li class="alt"><span>} </span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span><span class="comment">/* </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">提交参数说明: </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">$_POST['qq']---用户QQ </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">$_POST['g_tk']--这个参数很关键,获得这个参数,需要抓下发表时提交的post地址后面调用的g_tk=123456789, </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">路POST <a href="http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=123456789里的g_tk=123456789" target="_blank">http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=123456789里的g_tk=123456789</a> </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">$_POST['title']---文章标题,不得空 </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">$_POST['content']---文章内容,不得空 </span> </span></li><li><span><span class="comment"> </span> </span></li><li class="alt"><span><span class="comment">*/</span><span> </span></span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span>header(<span class="string">'Content-Type:text/html;charset=gb2312'</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span>set_time_limit(0); </span></li><li><span> </span></li><li class="alt"><span><span class="comment">//ob_end_clean(); </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//ob_start(); </span><span> </span></span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span><span class="comment">//获取cookie文件,不存在创建,并退出程序 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$cookiefile</span><span>=dirname(</span><span class="keyword">__FILE__</span><span>).</span><span class="string">'\qq_cookie.txt'</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">if</span><span>(!</span><span class="func">file_exists</span><span>(</span><span class="vars">$cookiefile</span><span>)){ </span></span></li><li><span> </span></li><li class="alt"><span><span class="func">echo</span><span> </span><span class="string">'qq_cookie.txt不存在,自动创建,请填写抓包的cookie<br>'</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span><span class="func">file_put_contents</span><span>(</span><span class="vars">$cookiefile</span><span>,</span><span class="string">''</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">die</span><span>(</span><span class="string">'程序退出'</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span>} </span></li><li><span> </span></li><li class="alt"><span><span class="comment">//存在,读取cookie </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">else</span><span>{ </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$cookie</span><span>=</span><span class="func">file_get_contents</span><span>(</span><span class="vars">$cookiefile</span><span>);</span><span class="comment">//登录cookie </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//$cookie=urlencode($cookie); </span><span> </span></span></li><li><span> </span></li><li class="alt"><span>} </span></li><li><span> </span></li><li class="alt"><span><span class="comment">//echo 'cookie:'.$cookie.'<br>'; </span><span> </span></span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span><span class="comment">//构成发表页,post数据等的重要信息 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//qq号码 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">if</span><span>(emptyempty(</span><span class="vars">$_POST</span><span>[</span><span class="string">'qq'</span><span>])||preg_match(</span><span class="string">'/[^0-9]/is'</span><span>,</span><span class="vars">$_POST</span><span>[</span><span class="string">'qq'</span><span>]))</span><span class="keyword">die</span><span>(</span><span class="string">'qq号码有误,必须数字'</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">else</span><span> </span><span class="vars">$qq</span><span>=</span><span class="vars">$_POST</span><span>[</span><span class="string">'qq'</span><span>];</span><span class="comment">//qq号 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">if</span><span>(emptyempty(</span><span class="vars">$_POST</span><span>[</span><span class="string">'g_tk'</span><span>])||preg_match(</span><span class="string">'/[^0-9]/is'</span><span>,</span><span class="vars">$_POST</span><span>[</span><span class="string">'g_tk'</span><span>]))</span><span class="keyword">die</span><span>(</span><span class="string">'post重要参数g_tk不合法,必须数字,请使用抓包的值'</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$g_tk</span><span>=</span><span class="vars">$_POST</span><span>[</span><span class="string">'g_tk'</span><span>]; </span></span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span><span class="vars">$title</span><span>=emptyempty(</span><span class="vars">$_POST</span><span>[</span><span class="string">'title'</span><span>])?</span><span class="keyword">die</span><span>(</span><span class="string">'标题不得空'</span><span>):</span><span class="vars">$_POST</span><span>[</span><span class="string">'title'</span><span>];</span><span class="comment">//文章标题 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$content</span><span>=emptyempty(</span><span class="vars">$_POST</span><span>[</span><span class="string">'content'</span><span>])?</span><span class="keyword">die</span><span>(</span><span class="string">'内容不得空'</span><span>):</span><span class="vars">$_POST</span><span>[</span><span class="string">'content'</span><span>];</span><span class="comment">//内容 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span><span class="vars">$category</span><span>=</span><span class="string">'个人日记'</span><span>;</span><span class="comment">//分类 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$fabiao</span><span>=</span><span class="string">'http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk='</span><span>.</span><span class="vars">$g_tk</span><span>;//发表处理页 </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$referer</span><span>=</span><span class="string">'http://ctc.qzs.qq.com/qzone/v5/toolpages/fp_gbk.html'</span><span>;//来源页 </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$r1</span><span>=</span><span class="string">'http://user.qzone.qq.com/'</span><span>.</span><span class="vars">$qq</span><span>.</span><span class="string">'/infocenter'</span><span>;//列表访问来源页 </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$postdata</span><span>=</span><span class="string">'uin='</span><span>.</span><span class="vars">$qq</span><span>.</span><span class="string">'&category='</span><span>.urlencode(</span><span class="vars">$category</span><span>).</span><span class="string">'&title='</span><span>.urlencode(</span><span class="vars">$title</span><span>).</span><span class="string">'&content='</span><span>.urlencode(</span><span class="vars">$content</span><span>).</span><span class="string">'&html='</span><span>.urlencode(</span><span class="string">'<div class="blog_details_20110920">'</span><span>.</span><span class="vars">$content</span><span>.</span><span class="string">'</div>'</span><span>).</span><span class="string">'&tweetflag=0&cb_autograph=1&topflag=0&needfeed=0&g_tk='</span><span>.</span><span class="vars">$g_tk</span><span>.</span><span class="string">'&_fp_refer=http%3A%2F%2Fctc.qzs.qq.com%2Fqzone%2Fnewblog%2Fv5%2Feditor.html%3Fsource%3D1%7Chttp%3A%2F%2Fctc.qzs.qq.com%2Fqzone%2Fnewblog%2Fv5%2Feditor.html%3Fsource%3D1%3Chttp%3A%2F%2Fuser.qzone.qq.com%2F'</span><span>.</span><span class="vars">$qq</span><span>.</span><span class="string">'%2Fmain'</span><span>;</span><span class="comment">//post数据 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//$postdata=urlencode($postdata); </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//echo $postdata; </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="comment">//发送请求,获取源码 </span><span> </span></span></li><li><span> </span></li><li class="alt"><span><span class="vars">$yuanma</span><span>=request(</span><span class="vars">$fabiao</span><span>,</span><span class="vars">$r1</span><span>,</span><span class="vars">$postdata</span><span>,</span><span class="vars">$cookie</span><span>,</span><span class="string">''</span><span>); </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">if</span><span>(</span><span class="func">strpos</span><span>(</span><span class="vars">$yuanma</span><span>,</span><span class="string">'发表成功'</span><span>))</span><span class="func">echo</span><span> </span><span class="vars">$title</span><span>.</span><span class="string">' 发表成功<br>'</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span><span class="keyword">else</span><span> </span><span class="func">echo</span><span> </span><span class="string">'发表失败:右键查看源码,可以看到具体错误'</span><span>.</span><span class="vars">$yuanma</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span>?> </span></li></ol>


php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
