【发布时间】:2012-08-22 14:29:05
【问题描述】:
我有一些 PHP 函数给出了两个 JSON 文件,将它们合并为一个以满足某些规范。但是,我需要使用 PHP 添加一个功能,该功能可以合并两个文件的内容字符串。这些字符串可能具有在它们之间的某些点上不同的文本。
例子
JSON-1
"elements":[
...
{
"type": "text",
"content": "It went up the tree! Then climbed down.",
},
...
]
JSON-2
"elements":[
...
{
"type": "text",
"content": "I saw your cat. It went up the tree! Then it run away!",
},
...
]
我需要合并后的文件像
JSON 合并
"elements":[
...
{
"type": "text",
"content": "<la>I saw your cat.</la> It went up the tree! <po>Then climbed down.<po> <li> Then it run away!</li>",
},
...
]
知道我该怎么做吗?我想过“爆炸”数组中的内容,然后相互迭代以查看匹配的内容。但是,类似的词,在不同的上下文中会匹配并弄乱代码!
【问题讨论】:
-
基本上你想用 JS 来区分这两个字符串。 This might help out.
-
问题中的 PHP 脚本已过时,PEAR 给了我已弃用的参考问题,例如
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Text\Diff.php on line 427 -
Google > php 字符串差异,问题已解决。