WordPress.org

Forums

The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] get_the_title and explode (3 posts)

  1. Igor Yavych
    Member
    Posted 5 years ago #

    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?

  2. Michael
    Forum Moderator
    Posted 5 years ago #

    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)

  3. Igor Yavych
    Member
    Posted 5 years ago #

    yea, it was encoded. changed - to code in explode and it worked. thanks :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.