cuk*_*eka 5 php replace internationalization
有没有办法实施德国报价(所谓'Gänsefüßchen')
„ („) and “ (“)
Run Code Online (Sandbox Code Playgroud)
在函数中转换英文引用的字符串
我说"你好"
至
我说"你好"
&bdquo应该只在开头应用,并且在字符串的末尾.
关于什么:
$input = 'I say "Hallo".';
$output = preg_replace('/"(.*?)"/', '„$1“', $input);
Run Code Online (Sandbox Code Playgroud)
它将所有均匀的报价替换为„“.
小智 2
这是该功能,经过测试并且工作正常。
注意: &bdquo仅适用于字符串的开头, &rdquo 仅适用于字符串的末尾。(hsz 的解决方案不遵循该规则)
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;
}
Run Code Online (Sandbox Code Playgroud)
测试:
echo(germanquotes('I am "glad" to write "functions" for "stackoverflow" users'));
Run Code Online (Sandbox Code Playgroud)