即时通讯尝试解码文本,这是我相信在WINDOWS-1251中提出的。 字符串看起来是这样的:没有分号编码
Агент
这应该代表了俄罗斯代理。这里的问题是:
- 我不能,除非我的每个数字
- 我不能做手工,因为我有一个10000行文本转换后加上分号这个字符串转换。
所以问题是,这是什么编码(无分号),我怎么能自动添加它们到每一行(正则表达式也许?),而不会破坏代码。
到目前为止,我一直在试图通过使用此代码来做到这一点:
应用逻辑
public function parseSentence((array) $sentences, $sentence, $i) {
if (strstr($sentence, '-')) {
$sentences[$i] = $this->explodeAndSplit('-', $sentence);
} else if (strstr($sentence, "'")) {
$sentences[$i] = $this->explodeAndSplit("'", $sentence);
} else if (strstr($sentence, "(")) {
$sentences[$i] = $this->explodeAndSplit("(", $sentence);
} else if (strstr($sentence, ")")) {
$sentences[$i] = $this->explodeAndSplit(")", $sentence);
} else {
if (strstr($sentence, '#')) {
$sentences[$i] = chunk_split($sentence, 6, ';');
}
return $sentences;
}
/**
* Explode and Split
* @param string $explodeBy
* @param string $string
*
* @return string
*/
private function explodeAndSplit($explodeBy, $string) {
$exp = explode($explodeBy, $string);
for ($j = 0; $j < count($exp); $j++) {
$exp[$j] = chunk_split($exp[$j], 6, ';');
}
return implode($explodeBy, $exp);
}
但很明显,这种做法是不正确一点(当然,完全不正确的) ,因为我没有考虑许多其他“特殊”角色。那么如何解决?
更新:
我使用流明的后端和AngularJS的前端。获取在Lumen(数据库/文本文件/ etc)中分析的所有数据,为AngularJS提供所谓的API路由来访问和检索数据。而事实是,在任何浏览器这个semicolonless编码工作巨大的,如果直接访问,但无法显示在角由于缺少分号
非常感谢这个惊人的演习,我的问题,简单的解决方案,真的很感谢 –
@IvanZhivolupov我的荣幸!我很高兴它帮助你解决了你的问题! – Darren