PHP正则表达式显示问题
我正在尝试创建一个用于对书名进行排序的字段,该字段会删除前导的“A,An,The”并将其附加到逗号和空格之后的强字符上。因此,“The Road”将变成“Road, The”,
听起来很简单,但下面的代码中有一些东西会导致 IE(没有其他浏览器)吐出一大堆乱码。
$node_field[0]['value'] = preg_replace(
'/^(A|An|The|a|an|the) (.*)/',
"$2\x00,$1",
$node->title
);
I'm trying to create a field for sorting book titles which strips the leading "A, An, The" and appends it to the strong after a comma and a space. Thus "The Road" would become "Road, The"
Sounds simple, but there's something in the code below which causes IE (no other browsers) to spit out a huge block of gibberish.
$node_field[0]['value'] = preg_replace(
'/^(A|An|The|a|an|the) (.*)/',
"$2\x00,$1",
$node->title
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该使用更像
如果我理解正确的话,这应该将任何“A ...”,“An ...”或“The ...”更改为“...,A”,“...,An ”和“...,The”,分别。
正则表达式模式中斜杠后面的 i 使其不区分大小写,这应该捕获 A、An 或 The 的所有版本。
You should use something more like
If I understand correctly, which should change any "A ...", "An ..." or "The ..." to "..., A", "..., An" and "..., The", respectively.
The i after the slash in the Regex pattern makes it case-insensitive, which should catch all versions of A, An, or The.