php代码不适用于德语äüö;
在下面的代码中,有两个变量来自mysql数据库,它们与几个txt文件的内容进行比较,包含这些变量的txt文件被输出到我的页面。褶皱也很棒。 现在我有两个问题。 除了内容之外,代码还指示txt文件的路径,我不知道如何隐藏它。我已经在这里花了几个小时尝试,但不幸的是没有结果 其次,变量$title已经包含一个ä、ö或ü。 那么代码就不起作用了 有人能帮我吗php代码不适用于德语äüö;,php,mysql,diacritics,Php,Mysql,Diacritics,在下面的代码中,有两个变量来自mysql数据库,它们与几个txt文件的内容进行比较,包含这些变量的txt文件被输出到我的页面。褶皱也很棒。 现在我有两个问题。 除了内容之外,代码还指示txt文件的路径,我不知道如何隐藏它。我已经在这里花了几个小时尝试,但不幸的是没有结果 其次,变量$title已经包含一个ä、ö或ü。 那么代码就不起作用了 有人能帮我吗 <?php /** * Searches for lines matching all regexp patterns. * * @
<?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));
});
?>