前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >连仕彤博客crayon-syntax-highlighter代码高亮插件Notice问题解决

连仕彤博客crayon-syntax-highlighter代码高亮插件Notice问题解决

作者头像
行 者
发布2018-06-01 14:53:17
4590
发布2018-06-01 14:53:17
举报
文章被收录于专栏:运维技术迷运维技术迷
《crayon-syntax-highlighter代码高亮插件Notice问题解决》
《crayon-syntax-highlighter代码高亮插件Notice问题解决》

在调试redis的时候,打开了wordpress的debug,看到了crayon-syntax-highlighter代码高亮插件出现了以上这个警告提示,其实也不影响功能的使用,就是看着不爽(^_^我有强迫症)。索性,花了点时间解决一下这个告警提示。

PHP7.1官方文档解释

New E_WARNING and E_NOTICE errors have been introduced when invalid strings are coerced using operators expecting numbers (+ – * / ** % << >> | & ^) or their assignment equivalents. An E_NOTICE is emitted when the string begins with a numeric value but contains trailing non-numeric characters, and an E_WARNING is emitted when the string does not contain a numeric value. 在使用(+ – * / ** % << >> | & ^) 运算时,例如a+b,如果a是开始一个数字值,但包含非数字字符(123a),b不是数字值开始时(b456),就会有A non-numeric value encountered警告。

解决过程

打开报错文件crayon_formatter.class.php,打印一下变量的数值,看是什么东西。

代码语言:javascript
复制
118             $toolbar_height = $font_size * 1.5 . 'px !important;';
119             var_dump($font_size);
120             echo '</br>';
121             var_dump($toolbar_height);
122             exit();

打印出来的结果看到$font_size的值是string类型,字符串和数值进行乘法运算,肯定是要报Notice的。

代码语言:javascript
复制
Notice: A non well formed numeric value encountered in /data/wwwroot/www.lianst.com/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118
string(16) "12px !important;" 
string(16) "18px !important;"

我们来使用intval方法把$font_size强制转换成数值之后再做乘法运算,应该就木有问题可。

代码语言:javascript
复制
118             $toolbar_height = $font_size * 1.5 . 'px !important;';
119             var_dump(intval($font_size));

使用intval方法把$font_size强制转换成数值之后可以看到$font_size的值已经转换成int类型了。

代码语言:javascript
复制
Notice: A non well formed numeric value encountered in /data/wwwroot/www.lianst.com/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118
int(12) 

解决方法

进入到crayon-syntax-highlighter插件的目录下面,找到crayon_formatter.class.php文件,将其报错行(118、119)处修改为如下代码即可。

代码语言:javascript
复制
118             $toolbar_height = intval($font_size) * 1.5 . 'px !important;';
119             $info_height = intval($font_size) * 1.4 . 'px !important;';

注: 1.参考资料:傲雪星枫CSDN

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • PHP7.1官方文档解释
  • 解决过程
  • 解决方法
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档