gpt4 book ai didi

javascript - explode 不能与破折号一起正常工作

转载 作者:行者123 更新时间:2023-11-29 17:58:50 24 4
gpt4 key购买 nike

我们有这个字符串:“Il Responsabile della Sicurezza nelle gallerie – 1° PARTE”,我们想要得到它的两个部分:

  1. Il Responsabile della Sicurezza nelle gallerie
  2. 1° PARTE

我们无法使用 explode() 获取它们在 字符

我们已经看到了this但每个答案都不适合我们。

我们已经尝试在前端使用 javascript,但没有得到积极的结果。

我们如何解决它?会不会是 charsted 的问题?(目前是 ISO-859-1,我们无法更改它)

最佳答案

您的字符串中有“非典型”破折号,它称为 Unicode Character 'EN DASH' (U+2013)
将其替换为utf-8 等效,然后,您将能够轻松拆分字符串:

$str = "Il Responsabile della Sicurezza nelle gallerie – 1° PARTE";
$endash = html_entity_decode('–', ENT_COMPAT, 'UTF-8');

$str = str_replace($endash, '-', $str);
print_r(explode("-",$str));

输出:

Array
(
[0] => Il Responsabile della Sicurezza nelle gallerie
[1] => 1° PARTE
)

http://www.fileformat.info/info/unicode/char/2013/index.htm

关于javascript - explode 不能与破折号一起正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36716556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com