PHP等效于JavaScript转义/解除 [英] PHP equivalent for javascript escape/unescape

查看:114
本文介绍了PHP等效于JavaScript转义/解除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个字符串:某些



当我在JS中逃避它时,我得到:%73%6F %6D%65%74%68%69%6E%67



所以我可以在JS中使用这个代码进行解码:

$ ($%73%6F%6D%65%74%68%69%6E%67');

我需要PHP中的转义函数,它将执行相同的操作(将编码强>至:%73%6F%6D%65%74%68%69%6E%67



如何做?

解决方案

PHP:

  rawurlencode(你的时髦的字符串); 

JS:


decodeURIComponent('你的%20funky%20string');


不要使用 escape ,因为它已被弃用。


Let's say I have a string: something

When I escape it in JS I get this: %73%6F%6D%65%74%68%69%6E%67

so I can use this code in JS to decode it:

 document.write(unescape('%73%6F%6D%65%74%68%69%6E%67'));

I need the escape function in PHP which will do the same (will encode something to : %73%6F%6D%65%74%68%69%6E%67)

How to do that ?

解决方案

PHP:

rawurlencode("your funky string");

JS:

decodeURIComponent('your%20funky%20string');

Don't use escape as it is being deprecated.

这篇关于PHP等效于JavaScript转义/解除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆