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!
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
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.