WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] get_the_title and explode

[Resolved] get_the_title and explode

  • Igor Yavych
    Participant

    @flyerua

    For some reason, explode is not working and just returns input string.
    Code:

    $str = get_the_title();
    $arr = explode("- Episode",$str);
    $res = $arr[0];
    echo $res;

    For example title was “Steins;Gate – Episode 15”, it returns whole title, instead of just “Steins;Gate”. If I supply string directly -> $str='Steins;Gate - Episode 15' instead of get_the_title it works as it is supposed to. Why I’m getting this problem?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael
    Forum Moderator

    @alchymyth

    check if the hyphen is not html character encoded;

    test example:

    $str = get_the_title();
    echo $str; //test output to check the title
    $arr = explode("- Episode",$str);
    $res = $arr[0];
    echo $res;

    then look at the output from the html code in the browser (not just on the screen)

    Igor Yavych
    Participant

    @flyerua

    yea, it was encoded. changed – to code in explode and it worked. thanks 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] get_the_title and explode’ is closed to new replies.