Simple explode operation with WordPress post titles

I have a music reviews blog and I use this format for titles in my wordpress:

Band – Album

Read More

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?

Related posts

Leave a Reply

2 comments

  1. 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…

    $title = htmlentities(get_the_title ());
    $str = explode ("&amp;#8211;", $title);
    $band = $str[0];
    $album = $str[1];
    echo "Band: ".$band;
    echo "<br>Album: ".$album;
    

    Thank you all