在php中rawurlencode与rawurlencode都是对字符进行编码的,下面我来给大家介绍urlencode和rawurlencode的区别,有需要了解的朋友可参考.
urlencode的用途就是编码字符串,把原字符串中所有除”-_”以为的非所有字母数字字符替换成百分号(%)后跟两位十六进制数,但是需要注意:由于历史原因会把空格替换+号.rawurlencode其实和urlencode一样,也是用来编码字符串的,唯一的不同是它是使用RFC1738 编码,也就是会把空格替换成%20.
它们对应的解码函数是urldecode和rawurldecode.参考官方网站的说明,urldecode解码给出的已编码字符串中的任何%##,加号(’+')被解码成一个空格字符;rawurldecode解码字符字符串中百分号(%)后跟两位十六进制.有两点区别,一是urldecode解码是对百分号(%)后任意两位字符都去会进行解码,例如%MN也会解码,但是会失败;rawurldecode则只会对百分号(%)后两位是十六进制(0-9A-F)的字符才会解码,二是urldecode会把+号解码为空格.
我们再看来两个函数在php官方的介绍吧.
urlencode — 编码 URL 字符串Report a bug 说明
string urlencode ( string $str )
此函数便于将字符串编码并将其用于 URL 的请求部分,同时它还便于将变量传递给下一页.Report a bug 参数str 要编码的字符串.
Report a bug 返回值
返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数,空格则编码为加号(+).此编码与 WWW 表单 POST 数据的编码方式是一样的,同时与 application/x-www-form-urlencoded 的媒体类型编码方式一样.由于历史原因,此编码在将空格编码为加号(+)方面与 RFC1738 编码(参见 rawurlencode())不同.
实例代码如下:
- Example #1 urlencode() 例子
- <?php
- echo '<a href="mycgi?foo=', urlencode($userinput), '">';
- ?>
- Example #2 urlencode() 与 htmlentities() 例子
- <?php
- $query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar);
- echo '<a href="mycgi?' . htmlentities($query_string) . '">';
- ?>
rawurlencode — 按照 RFC 1738 对 URL 进行编码Report a bug 说明
string rawurlencode ( string $str )
根据 » RFC 3986 编码指定的字符.Report a bug 参数str 要编码的 URL.
Report a bug 返回值
返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数.这是在 » RFC 3986 中描述的编码,是为了保护原义字符以免其被解释为特殊的 URL 定界符,同时保护 URL 格式以免其被传输媒体(像一些邮件系统)使用字符转换时弄乱.
实例代码如下:
- Example #1 在 FTP URL 里包含一个密码
- <?php
- echo '<a href="ftp://user:', rawurlencode('foo @+%/'),
- '@ftp.example.com/x.txt">';
- ?>
以上例程会输出:
波比源码 » php urlencode和rawurlencode的区别介绍
buy levofloxacin online cheap levofloxacin 500mg oral
buy dutasteride order tamsulosin 0.2mg without prescription buy zofran 4mg for sale
brand aldactone 100mg valacyclovir 500mg generic order generic diflucan 100mg
acillin canada bactrim online order buy erythromycin generic
oral sildenafil buy methocarbamol generic methocarbamol 500mg
suhagra 50mg for sale sildalis canada estradiol 2mg us
tadalafil 20mg pill order voltaren 50mg for sale order generic voltaren 50mg
order isotretinoin 40mg generic order accutane 40mg generic buy zithromax 500mg sale
buy indomethacin 50mg generic buy indocin online cheap trimox 500mg over the counter
tadalafil generic male enhancement products cost sildenafil 50mg
generic arimidex Viagra 50 mg buy viagra sale
acheter 40mg du cialis sildenafil 25mg prix acheter 200mg gГ©nГ©rique viagra en france
brand doxycycline doxycycline 100mg over the counter lasix without prescription
altace pills oral irbesartan 300mg azelastine 10 ml usa
buy clonidine 0.1mg online cheap generic catapres tiotropium bromide sale
order hytrin 1mg generic purchase arava generic azulfidine 500mg cheap
brand alendronate 70mg purchase panadol sale cost famotidine 20mg
buy olmesartan 20mg pills generic benicar 10mg diamox 250 mg drug
order tadalafil 5mg online cheap order cialis 40mg without prescription female viagra pill
purchase tadalafil pill cost pyridium amantadine 100 mg drug
revia order order femara 2.5 mg pill order aripiprazole 20mg pills
dapsone 100 mg oral buy dapsone 100mg for sale buy aceon 4mg
order luvox 50mg online cheap purchase nizoral pills purchase glipizide online
zithromax online prednisolone 10mg ca buy neurontin 600mg
cialis 10mg without prescription order tadalafil for sale sildenafil overnight shipping
purchase furosemide generic order lasix sale order plaquenil 200mg online cheap
itraconazole for sale online order tindamax 300mg without prescription purchase tindamax sale
buy glucophage 1000mg without prescription cialis 5mg buy tadalafil 10mg generic
buy amlodipine generic usa cialis sales tadalafil 5mg sale
purchase clozaril online buy decadron online oral dexamethasone 0,0,5 mg
omeprazole online buy term papers help play casino
generic lopressor 100mg order atenolol 100mg pill buy vardenafil pill
professional paper writers essays writing sildenafil 100mg pills for men
brand triamcinolone 10mg order aristocort 10mg generic clarinex usa
dapoxetine 60mg usa priligy 30mg tablet order synthroid sale
orlistat 120mg uk diltiazem online order buy acyclovir 400mg
generic cialis online plavix 150mg over the counter buy plavix 75mg without prescription
order methotrexate 10mg online cheap order methotrexate 10mg without prescription order metoclopramide 20mg generic
motilium for sale online sumycin 500mg us cheap flexeril 15mg
order imitrex online purchase imitrex online cheap order dutasteride pill
colchicine 0.5mg pills order colchicine online cheap free online roulette
ranitidine cheap mobic 15mg uk celebrex 100mg for sale
real money online casinos usa best poker online real money gambling addiction
flomax 0.2mg without prescription brand tamsulosin 0.4mg spironolactone for sale
cialis 40mg oral order tadalafil 10mg pill ciprofloxacin generic
buy tadalafil 10mg pills cialis for men cheap viagra for sale
sildenafil over counter sildenafil uk tadalafil 20mg for sale
buy cefuroxime 500mg generic order ceftin generic buy methocarbamol pill