本文介绍了将英语引号替换为德语引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以实现德语引号(所谓的Gänsefüßchen")
is there a way to implement german quotes (so-called 'Gänsefüßchen')
„ („) and “ (")
在转换像
到
& bdquo只应在字符串的开头,而& ldquo则应在字符串的结尾.
the &bdquo should only apply at the beginning, the &ldquo at the end of an string.
推荐答案
此处是经过测试且可以正常运行的功能.
Here is the function, tested and works fine.
注意:& bdquo仅在字符串的开头应用,而在字符串的末尾仅使用& rdquo. (hsz的解决方案不遵循该规则)
Note: the &bdquo applies only at the beginning, the &rdquo only at the end of an string. (hsz's solution isn't following that rule)
function germanquotes($text){
$size = strlen($text);
$i=0;
$replace = array();
$replace['one'] = array();
$replace['two'] = array();
while($i < $size)
{
if($text[$i] == '"')
{
if($text[$i-1] == " " || empty($text[$i-1]))
{
$replace['one'][] = $i;
}
elseif($text[$i+1] == " " || empty($text[$i+1]))
{
$replace['two'][] = $i;
}
}
$i++;
}
$y = 0;
$it = 0;
foreach($replace['one'] as $ghh)
{
$text = substr_replace($text, '„', ($ghh+$y), 1);
$y += 6;
$it++;
}
$to=0;
$i=1;
$u=1;
foreach($replace['two'] as $ghhd)
{
$text = substr_replace($text, '”', ($ghhd-1+$to+((8*$i)-($u*1))), 1);
$i++;
$u +=2;
$to +=6;
}
return $text;
}
测试:
echo(germanquotes('I am "glad" to write "functions" for "stackoverflow" users'));
这篇关于将英语引号替换为德语引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!