【问题标题】:Why this pattern with __FILE__ under preg_quote() is not matching the directory path?为什么 preg_quote() 下的 __FILE__ 模式与目录路径不匹配?
【发布时间】:2017-10-21 15:59:00
【问题描述】:

这个模式在__FILE__preg_quote( $str, '/' )

/^C\:\\xampp\\apps\\wordpress\\htdocs\\wp\-content\\themes\\themename\\inc\\fonts\/uploads\/[^\/\\]+(\/|\\)/

与此目录路径不匹配

C:\xampp\apps\wordpress\htdocs\wp-content\themes\themename\inc\fonts/uploads\BELLABOO\

这里(只排除BELLABOO\BELLABOO-Regular.otf

C:\xampp\apps\wordpress\htdocs\wp-content\themes\themename\inc\fonts/uploads\BELLABOO\BELLABOO\BELLABOO-Regular.otf

但是在使用自定义模式执行此操作时,它是匹配的:

$pattern = '/.+inc(\/|\\\\)fonts(\/|\\\\)uploads(\/|\\\\)[^\/\\\\]+(\/|\\\\)/';
// $pattern = '/^C\:\\xampp\\apps\\wordpress\\htdocs\\wp\-content\\themes\\themename\\inc\\fonts\/uploads\/[^\/\\]+(\/|\\)/'; Not working!
preg_match( $pattern, $font_path, $matches );
echo $matches[0]; // C:\xampp\apps\wordpress\htdocs\wp-content\themes\themename\inc\fonts/uploads\BELLABOO\

如何使它与第一个模式一起工作?

【问题讨论】:

  • 可以分享__FILE__的值吗?

标签: php regex path directory preg-quote


【解决方案1】:

改变图案:

/^C\:\\xampp\\apps\\wordpress\\htdocs\\wp\-content\\themes\\themename\\inc\\fonts\/uploads\/[^\/\\]+(\/|\\)/

与:

/^C\:\\xampp\\apps\\wordpress\\htdocs\\wp\-content\\themes\\themename\\inc\\fonts\/uploads\\[^\/\\]+(\/|\\)/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    • 2023-03-15
    相关资源
    最近更新 更多