我有一个InDesign脚本,可以将页面转换为JSON格式.
然而,这带有智能的"卷曲"双引号而不是正常的("").当然这会产生无效的JSON文件.
试图解决这个问题,因为我需要在这些文件上用PHP做一些其他的操作,我试图接受这个问题并在文件上传中解决它.
事实证明,该功能仅适用于InDesign在Windows PC中生成的引号(并非总是).如果您在MAC上运行脚本并上传文件,它将完全不起作用,因为编码似乎不同.我尝试了其他解决方案,但是,它们根本不会产生任何结果.
这是脚本.
function quoteReplacer($file)
{
$string = file_get_contents($file);
$string = to_utf8($string);
$bits = array('\xe2\x80\x9c', '\xe2\x80\x9d', '\xe2\x80\x98', '\xe2\x80\x99','â','â');
$string = str_replace($bits,'"',$string);
file_put_contents($file,$string);
//file_put_contents($file,$string);
}
function to_utf8( $string ) {
return iconv( 'CP1250', 'UTF-8', $string);
}
Run Code Online (Sandbox Code Playgroud)
这个脚本应该工作:
// First, replace UTF-8 characters.
$text = str_replace(
array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
array("'", "'", '"', '"', '-', '--', '...'),
$text);
// Next, replace their Windows-1252 equivalents.
$text = str_replace(
array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
array("'", "'", '"', '"', '-', '--', '...'),
$text);
Run Code Online (Sandbox Code Playgroud)
替换所有可能堵塞你的JSON的奇怪角色.礼貌:链接.
或者,您可以让他们在所有工作站上关闭它,通过按Command+ Shift+ Option+ the quote key next to Enter为MAC,pc上的等价物可能是ctrl+ alt+ shift+,'或者您可以在首选项中找到它.
| 归档时间: |
|
| 查看次数: |
2487 次 |
| 最近记录: |