php - _$_15d1[19]匹配,并输出其中的数字?
高洛峰
高洛峰 2017-04-10 18:02:54
[PHP讨论组]
    this[_$_15d1[19]] = function() {
        this[_$_15d1[10]] = touchSupport ? _$_15d1[20] : _$_15d1[21];
        this[_$_15d1[11]] = touchSupport ? _$_15d1[20] : _$_15d1[22];
        this[_$_15d1[12]] = touchSupport ? _$_15d1[23] : _$_15d1[24];
        this[_$_15d1[13]] = touchSupport ? _$_15d1[25] : _$_15d1[26];
        this[_$_15d1[14]] = this[_$_15d1[28]]()[_$_15d1[27]](/[H|h]idden/, _$_15d1[6]) + _$_15d1[29];
        this[_$_15d1[30]]()
    };

代码如上图类似。想要匹配 _$_15d1[19]这种,并输出其中的数字。求帮助。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(1)
高洛峰
<?php 
$text = 'this[_$_15d1[19]] = function() {
        this[_$_15d1[10]] = touchSupport ? _$_15d1[20] : _$_15d1[21];
        this[_$_15d1[11]] = touchSupport ? _$_15d1[20] : _$_15d1[22];
        this[_$_15d1[12]] = touchSupport ? _$_15d1[23] : _$_15d1[24];
        this[_$_15d1[13]] = touchSupport ? _$_15d1[25] : _$_15d1[26];
        this[_$_15d1[14]] = this[_$_15d1[28]]()[_$_15d1[27]](/[H|h]idden/, _$_15d1[6]) + _$_15d1[29];
        this[_$_15d1[30]]()
    };';
preg_match_all('/_\$_.*?\[([0-9]+)\]/i', $text, $arr);
echo implode($arr[0], ',');
echo '<br>';
echo implode($arr[1], ',');

输出

_$_15d1[19],_$_15d1[10],_$_15d1[20],_$_15d1[21],_$_15d1[11],_$_15d1[20],_$_15d1[22],_$_15d1[12],_$_15d1[23],_$_15d1[24],_$_15d1[13],_$_15d1[25],_$_15d1[26],_$_15d1[14],_$_15d1[28],_$_15d1[27],_$_15d1[6],_$_15d1[29],_$_15d1[30]
19,10,20,21,11,20,22,12,23,24,13,25,26,14,28,27,6,29,30

替换

$text = 'this[_$_15d1[19]] = function() {
        this[_$_15d1[10]] = touchSupport ? _$_15d1[20] : _$_15d1[21];
        this[_$_15d1[11]] = touchSupport ? _$_15d1[20] : _$_15d1[22];
        this[_$_15d1[12]] = touchSupport ? _$_15d1[23] : _$_15d1[24];
        this[_$_15d1[13]] = touchSupport ? _$_15d1[25] : _$_15d1[26];
        this[_$_15d1[14]] = this[_$_15d1[28]]()[_$_15d1[27]](/[H|h]idden/, _$_15d1[6]) + _$_15d1[29];
        this[_$_15d1[30]]()
    };';
$i = 0;
$data = array(4, 3, 2, 1);
$newText = preg_replace_callback(
    '/(_\$_.*?\[)([0-9]+)(\])/i',
    function($match) use ($data, &$i){
        $key = empty($data[$i]) ? $match[2] : $data[$i] ;
        $str = $match[1].$key.$match[3];
        $i++;
        return $str;
    },
    $text
); 
echo $newText;

输出

this[_$_15d1[4]] = function() {
        this[_$_15d1[3]] = touchSupport ? _$_15d1[2] : _$_15d1[1];
        this[_$_15d1[11]] = touchSupport ? _$_15d1[20] : _$_15d1[22];
        this[_$_15d1[12]] = touchSupport ? _$_15d1[23] : _$_15d1[24];
        this[_$_15d1[13]] = touchSupport ? _$_15d1[25] : _$_15d1[26];
        this[_$_15d1[14]] = this[_$_15d1[28]]()[_$_15d1[27]](/[H|h]idden/, _$_15d1[6]) + _$_15d1[29];
        this[_$_15d1[30]]()
    };
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号