php代码不适用于德语ä,ü,ö

时间:2017-02-02 19:12:22

标签: php mysql diacritics

在下面的代码中,有两个变量来自mysql数据库,它们与几个txt文件的内容进行比较,包含变量的txt文件输出到我的页面。折叠也很精彩。 现在这是我的两个问题。 除了内容之外,代码还指出了txt文件的路径,我不知道如何隐藏它。已经在这里花了几个小时尝试,但遗憾的是没有结果。

其次,变量$ title已包含ä,ö或ü。 然后代码不再起作用了!

有人能帮帮我吗?

<?php
/**
 * Searches for lines matching all regexp patterns.
 *
 * @param string $dir Path to directory with text files
 * @param array $patterns AWK patterns without regexp markers ('/')
 * @return array Files matching all patterns
 * @throws InvalidArgumentException
 */
function grepDir($dir, array $patterns, callable $callback) {
  if (!$patterns) {
    throw new InvalidArgumentException("Invalid patterns");
  }

  // Build command as awk '/pattern1/ && /pattern2/ && ... path-to-file'
  $awk_script = '/' . implode('/ && /', $patterns) . '/';
  $awk_script = escapeshellarg($awk_script);
  $command_format = "awk $awk_script %s";

  try {
    $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));

    $it->rewind();
    while ($it->valid()) {
      if (!$it->isDot()) {
        $file_path = $it->key();
        $command = sprintf($command_format, $file_path);
        $output = null;
        exec($command, $output, $exit_status);

        if ($exit_status) {
          trigger_error("Command failed: $command");
          continue;
        }

        if ($output) {
          $callback($file_path, $output);
        }
      }

      $it->next();
    }
  } catch (Exception $e) {
    trigger_error($e->getMessage());
    return false;
  }
  return true;
}
$title = $this->item->title;
$ergebnis = $extraField->value;
$dir = './webtt_alt/daten';
$patterns = [ $title , $ergebnis ];
grepDir($dir, $patterns, function ($file_path, array $output) {
  printf("%s\n\n%s\n\n", $file_path, implode(PHP_EOL, $output));
});
?>

0 个答案:

没有答案
相关问题