str urlencode($string):此功能是方便的编码字符串时要在URL的查询的一部分用来作为一种方便的方法传递变量到下一页.
我写了这个简单的函数,创建一个GET查询的网址()从一个数组,代码如下:
function encode_array($args) { if(!is_array($args)) return false; $c = 0; $out = ''; foreach($args as $name => $value) { if($c++ != 0) $out .= '&'; $out .= urlencode("$name").'='; if(is_array($value)) { $out .= urlencode(serialize($value)); }else{ $out .= urlencode("$value"); } } return $out . " "; }
如果有在$args数组数组,它们将被序列化之前进行了urlencoded,代码如下:
echo encode_array(array('foo' => 'bar')); // foo=bar echo encode_array(array('foo&bar' => 'some=weird/value')); // foo%26bar=some%3Dweird%2Fvalue echo encode_array(array('foo' => 1, 'bar' => 'two')); // foo=1&bar=two echo encode_array(array('args' => array('key' => 'value'))); // args=a%3A1%3A%7Bs%3A3%3A%22key%22%3Bs%3A5%3A%22value%22%3B%7D
我需要一个在PHP函数在JavaScript中做完整的逃生功能相同的工作,我花一些时间不找到它,但findaly我决定写我自己的代码,因此,为了节省时间,代码如下:
function fullescape($in) { $out = ''; for ($i=0;$i<strlen($in);$i++) { $hex = dechex(ord($in[$i])); if ($hex=='') $out = $out.urlencode($in[$i]); }else{ $out = $out .'%'.((strlen($hex)==1) ? ('0'.strtoupper($hex)):(strtoupper($hex))); } $out = str_replace('+','%20',$out); $out = str_replace('_','%5F',$out); $out = str_replace('.','%2E',$out); $out = str_replace('-','%2D',$out); return $out; }
我需要为UTF8的编码和解码网址,我想出了这些非常简单fuctions,希望这会有所帮助,代码如下:
function url_encode($string){ return urlencode(utf8_encode($string)); } function url_decode($string){ return utf8_decode(urldecode($string)); }
urlencode:是指针对网页url中的中文字符的一种编码转化方式,最常见的就是Baidu、Google等搜索引擎教程中输入中文查询时候,生成经过 Encode过的网页URL,urlencode的方式一般有两种一种是传统的基于GB2312的Encode(Baidu、Yisou等使用),一种是 基于utf-8的Encode(Google,Yahoo等使用),本工具分别实现两种方式的Encode与Decode.
中文 -> GB2312的Encode -> %D6%D0%CE%C4
中文 -> utf-8的Encode -> %E4%B8%AD%E6%96%87
如果要使用utf-8的Encode,有两种方法.
一、将文件存为utf-8文件,直接使用urlencode、rawurlencode即可.
二、使用mb_convert_encoding函数.
<?php $url = 'http://www.phprm.com/中文.rar'; echo urlencode(mb_convert_encoding($url, 'utf-8', 'gb2312'))." "; echo rawurlencode(mb_convert_encoding($url, 'utf-8', 'gb2312'))." "; //http%3A%2F%2Fwww.phprm.com%2F%E4%B8%AD%E6%96%87.rar
教程链接:
随意转载~但请保留教程地址★

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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.
