如何在 – 处拆分 WordPress 标题?在 PHP 中?
我正在开发我的 WordPress 博客,需要获取帖子的标题并将其拆分为“-”。事实是,它不起作用,因为在源代码中它是&ndash,当我在网站上查看结果时,它是一个“长减号”(–)。将这个长减号复制并粘贴到某个编辑器中会使其成为普通的减号 (-)。我不能在“-”或&ndash处分裂,但不知何故它一定是可能的。当我创建这篇文章时,我只是输入了“-”(减号),但在某个地方它会自动转换为 – 。
有什么想法吗?
谢谢!
I am working on my Wordpress blog and its required to get the title of a post and split it at the "-". Thing is, its not working, because in the source its &ndash and when I look at the result on the website, its a "long minus" (–). Copying and pasting this long minus into some editor makes it a normal minus (-). I cant split at "-" nor at &ndash, but somehow it must be possible. When I created the article, I just typed "-" (minus), but somewhere it gets converted to – automatically.
Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我找到了。我记得我遇到过类似的问题,当我在帖子中粘贴代码时,引号在向读者显示时会转换为 em-quad 引号。
我发现在 /wp-include/formatting.php 第 56 行(wordpress ver 3.3.1)中,它定义了一些需要替换的字符
,并在第 85 行中进行了替换
I think I found it. I remember that I have meet the similar problem that when I paste code in my post the quote mark transform to an em-quad one when display to readers.
I found that is in /wp-include/formatting.php line 56 (wordpress ver 3.3.1), it defined some characters need to replace
and in line 85 it make an replacement
如果你想在“-”字符处分割字符串,基本上你必须用空格替换“-”。
试试这个:
这些行在“-”处分割字符串。例如,如果您有 my-word-test,它将回显“my word test”。我希望它有帮助。
有关 str_replace 函数的更多信息,请单击此处。
如果您想以 WordPress 风格执行此操作,请尝试使用过滤器。我建议将这些行放入您的functions.php 文件中:
现在,每次您在循环中使用the_title 时,标题都会被转义。
If you want to split a string at the "-" character, basically you must replace "-" with a space.
Try this:
These lines splits the string at the "-". For example, if you have my-word-test, it will echo "my word test". I hope it helps.
For more information about the str_replace function click here.
If you want to do this in a WordPress style, try using filters. I suggest placing these lines in your functions.php file:
Now, everytime you use the_title in a loop, the title will be escaped.