douxi3554 2016-06-16 12:55
浏览 48
已采纳

迁移网站:eregi到preg_match?

I'm in the process of migrating a horrible drupal site to a new server - a server with a newer version of PHP. Checking the site I get the following error:

Deprecated: Function ereg() is deprecated in /var/sites/n/nanohex.org/public_html/includes/file.inc on line 902

Line 902 looks like the following:

elseif ($depth >= $min_depth && ereg($mask, $file)) {

My understanding is that ereg is no longer used and I need to replace with pregmatch.

Changing the code the following...

 elseif ($depth >= $min_depth && preg_match('/\.([^\.]*$)/', $mask, $file)) {

throws up this error instead:

Warning: basename() expects parameter 1 to be string, array given in /var/sites/n/nanohex.org/public_html/includes/file.inc on line 905

Line 905 looks like this:

$basename = basename($file);

What am I doing wrong?

  • 写回答

1条回答 默认 最新

  • douba4824 2016-06-16 12:59
    关注

    The matches are in the array $file. You have to use the second entry in this array:

    $basename = basename($file[1]);
    

    But I guess your preg_match should be:

    preg_match('/\.([^\.]*$)/', $file)
    

    and then:

    $basename = basename($file);
    

    is OK.

    preg_match doc

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?