- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚将服务器上的PHP从php 5更新到了php 7,并且收到以下警告:
警告:preg_replace_callback()[function.preg-replace-callback0]:要求参数2'chr(\ 1)'为有效的回调
警告:preg_replace_callback()[function.preg-replace-callback0]:要求参数2'chr(0x \ 1)'为有效的回调
警告:preg_replace_callback()[function.preg-replace-callback0]:要求参数2'chr(\ 1)'为有效的回调
警告:preg_replace_callback()[function.preg-replace-callback0]:要求参数2'chr(0x \ 1)'为有效的回调
这是PHP代码:
private function _decode( $source )
{
$source = html_entity_decode($source, ENT_QUOTES, 'UTF-8');
$source = preg_replace_callback('/&#(\d+);/me',"chr(\\1)", $source);
$source = preg_replace_callback('/&#x([a-f0-9]+);/mei',"chr(0x\\1)", $source);
return $source;
}
$source = preg_replace_callback('/&#x([a-f0-9]+);/mei',"chr(0x\\1)", $source);
最佳答案
如the PHP 7.0 migration guide中所述,不再支持/e
修饰符(PREG_REPLACE_EVAL
)。您需要使用可调用函数,而不是将被视为函数的字符串。在您的情况下,将字符串函数chr(0x\\1)
替换为Closure:
$source = preg_replace_callback(
'/&#x([a-f0-9]+);/mi',
fn($m) => chr(hexdec('0x'.$m[1])),
$source
);
\\1
以产生有效的PHP十六进制(如
0x21
)在可调用对象中不再起作用:您需要
hexdec
调用才能实现相同目的。
$source = preg_replace_callback(
'/&#x([a-f0-9]+);/mi',
function ($m) { return chr(hexdec('0x'.$m[1])); }, // Now a Closure
$source
);
关于php - 警告:preg_replace_callback():需要参数2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44980924/
我在文本中有几个“短代码” block ,我想使用 preg_replace_callback 将它们替换为一些 HTML 实体。 短代码的语法很简单: [block:type-of-the-bloc
我有一个正则表达式的问题。 我正在使用 token ,我必须解析这样的文本: Just some random text #IT=AB|First statement# #xxxx=xxx|First
我有这个代码: $string = 'The quick brown fox jumped over the lazy dog and lived to tell about it to his cr
我有正则表达式来查找所有带百分比的数字 (100|\d\d|\d)\% - 此正则表达式已给出,我不能更改它。我有输入字符串: Lorem ipsum 10% dolor, 8%sit amet 50
今天我开始理解具有已知值的 preg_replace_callback,得到了一些很大的帮助。但现在我想处理未知的值。 $string = ' texttextmore textPage 6Page
我使用 Wordpress 插件 Codecolorer ( https://wordpress.org/plugins/codecolorer/ ),在 PHP 7 上我遇到了这个问题: /**
我有以下 HTML 语句 [otsection]Wallpapers[/otsection] WALLPAPERS GO HERE [otsection]Videos[/otsection] VIDE
我刚刚将服务器上的PHP从php 5更新到了php 7,并且收到以下警告: 警告:preg_replace_callback()[function.preg-replace-callback0]:要求
使用 PHP preg_replace_callback函数,我想用子字符串“X1X2”替换模式“function([x1,x2])”的出现,用子字符串“X1X2X3”替换“function([x1,
这个问题已经有答案了: Are PHP Variables passed by value or by reference? (16 个回答) 已关闭 8 年前。 我有一个看起来像这样的函数... f
有没有一种简单的方法来跟踪 preg_replace_callback 中的当前索引?我需要替换以下内容,例如: {get}50{end get} 使用 $someArray[50] 的值。我不能只将
我有一个问题要问你! 通常,如果您在 OOP 上下文中调用回调函数,则必须使用 array(&$this, 'callback_function') 这就是我想出来的。 但现在我想在外部类中调用回调,
这个问题已经有答案了: Are PHP Variables passed by value or by reference? (16 个回答) 已关闭 8 年前。 我有一个看起来像这样的函数... f
我正在尝试将使用 javascript 替换函数的 javascript 翻译成 PHP。 js 替换有一个使用偏移量和源字符串值的回调。我尝试使用 preg_replace_callback js
我正在尝试创建一个网络应用程序,它将任何选定的网页转换为简单的英语形式。我有一个逐字翻译存储在 MySQL 数据库中。到目前为止我有这个代码。它有效,但似乎只能在几个标签中完成我想要的操作,而不是整个
我有一个 JavaScript 函数(不是普通的 JavaScript) function formatString () { var args = jQuery.makeArray(argu
所以...所有属性都已完美排序 但是 如何将它们替换(/合并)回原来的 $css 值? 这段代码几乎是不言自明的,但我已经添加了我期望得到的内容以防万一……这里需要进行一些小调整:) '. p
我在一些使用旧系统的页面上有链接,例如: This is a link 他们需要转换到新系统,例如: This is a link 我可以使用 preg_replace t0 更改一些我需要的内容,但
我正在尝试创建一个 REGEX 输入 > quote the rest of it > another paragraph the rest of it 和OUTPUT quotethe rest o
我正在尝试用传递的数组中的值替换 $text 中的 {{key}} 项。但是当我尝试添加 print_r 以查看发生了什么时,我收到了 Undefined variable: kvPairs 错误。如
我是一名优秀的程序员,十分优秀!