I have a music reviews blog and I use this format for titles in my wordpress:
Band – Album
So I want to do something seemingly simple as “explode” the title:
$title = get_the_title ();
$str = explode ("-", $title);
$band = $str[0];
$album = $str[1];
echo "Band: ".$band;
echo "<br>Album: ".$album;
The problem is that it outputs the whole title in variable $band. Explode doesn’t work with hyphen/dash (-). However, if I use any other “separator” in the explode function, it works properly.
Any idea about what’s the matter here?
Solved! …with htmlentities. Seems that my wordpress encode hyphens with a different code. It may be because the font used in my theme, I don´t know…
Thank you all
Created phpfiddle with your data and is working great:
http://phpfiddle.org/main/code/f42-tni
You must have some other char in you string.
Adding code from phpfiddle..