doumo3903 2018-11-27 08:55
浏览 110

PHP 7.2升级代码 - REGEX使用未定义的常量

atm i want to prepare my code to upgrade from PHP 7.0 to 7.2. For this i wrote my own small search & replace script which uses REGEX rules to find incompatiblity code and if possible fix them with preg_replace.

Code Error:

"Warning: Use of undefined constant..."

For this i wrote the follow REGEX:

$search_strings['7.0 to 7.2']['search'][]   = '#(\[([^0-9$]\w+)\](?!\'))#i'; 
$search_strings['7.0 to 7.2']['replace'][]  = '[\'$2\']';

This works with normal Arrays in code but if they are nested inside a MySQL Query or inside a echo/declaration value it still sucks:

The most rules worked fine, but now i want to fix the follow:

$MyArray[array_level1][] = 'sdfsdf [test] my code';

will replace to(wrong):

$MyArray['array_level1'][] = 'sdfsdf ['test'] my code';

should be:

$MyArray['array_level1'][] = 'sdfsdf [test] my code';

or

$sel = "SELECT * FROM $tbl[my_table_name] WHERE request LIKE '$myArray[test]%' LIMIT 0,1";

will replace to(wrong):

$sel = "SELECT * FROM $tbl['my_table_name'] WHERE request LIKE '$myArray['test']%' LIMIT 0,1";

should be(i think for this is an extra regex needed because to complex?):

$sel = "SELECT * FROM ".$tbl['my_table_name']." WHERE request LIKE '".$myArray['test']."%' LIMIT 0,1";

Which also wrong...i testet several REGEX but didn´t find a solution, i think i need to optimize my negative lookahead, here is my example:

Regex Example

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!