【问题标题】:Migrating a site: ereg to pregmatch?迁移站点:ereg 到 preg_match?
【发布时间】:2016-10-18 00:17:27
【问题描述】:

我正在将一个糟糕的 drupal 站点迁移到一个新服务器 - 一个具有较新版本 PHP 的服务器。检查网站我收到以下错误:

已弃用:函数 ereg() 在 /var/sites/n/nanohex.org/public_html/includes/file.inc 第 902 行已弃用

第 902 行如下所示:

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

我的理解是ereg已经不用了,需要换成pregmatch。

修改代码如下...

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

改为抛出此错误:

警告:basename() 期望参数 1 为字符串,数组在 /var/sites/n/nanohex.org/public_html/includes/file.inc 第 905 行给出

第 905 行如下所示:

$basename = basename($file);

我做错了什么?

【问题讨论】:

    标签: php preg-match ereg


    【解决方案1】:

    匹配项在数组$file 中。您必须使用此数组中的第二个条目:

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

    但我猜你的 preg_match 应该是:

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

    然后:

    $basename = basename($file);
    

    没问题。

    preg_match doc

    【讨论】:

      猜你喜欢
      • 2011-07-12
      • 2016-03-15
      • 2012-10-04
      • 2015-10-24
      • 2015-12-22
      • 2013-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多