php - 如何从js代码中获取字符串值

标签 php javascript preg-match urldecode

我想获取字符串值,然后使用urldecode()

Javascript

document.write(unescape('%46%43%20%42%72%61%73%6f%76%20%76%73%2e%20%43%53%4d%53%20%49%61%73%69'));

PHP

$string = "document.write(unescape('%46%43%20%42%72%61%73%6f%76%20%76%73%2e%20%43%53%4d%53%20%49%61%73%69'));";

preg_match('/document.write(unescape(\'.*\'));/', $string,$matches);
var_dump($matches);

但是这返回array(0) { }

最佳答案

你可以试试

$string = "document.write(unescape('%46%43%20%42%72%61%73%6f%76%20%76%73%2e%20%43%53%4d%53%20%49%61%73%69'));";
preg_match('/document.write\(unescape\(\'(.*)\'\)\);/', $string,$matches);
var_dump($matches[1]);

输出

string '%46%43%20%42%72%61%73%6f%76%20%76%73%2e%20%43%53%4d%53%20%49%61%73%69' (length=69)

关于php - 如何从js代码中获取字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12785870/

相关文章:

javascript - 在 process.stdin 的可读流中插入条件语句

php - 如何将组与 preg_match 一起使用?

php - Wordpress:列出所有 URL/路由

php - 在类包装器中缓存 PDO 准备语句

javascript - json 响应日期格式为用户定义的日期格式

javascript - 有没有办法检测到 css 转换已被中止/中断?

php - 高级正则表达式替换。检查是否在 <script> 标签中

php - 我如何预匹配希伯来语中的单词

php - Joomla 3.4.3 - configuration.php 不可写

php - Laravel 验证存在于不存在的地方