WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Comparing strings doesn't work !?!? (7 posts)

  1. pikkabbu
    Member
    Posted 2 years ago #

    Hi,
    First, let me tell you that I'm modifying a theme's file and I don't know php.

    Two: I know others programing languages, so I'm not completely dummy.

    I need to modify just a bit the page that displays the portfolio, so that only pictures belonging to a selected category will be shown.

    But the test
    If $myvariable = "mystring" fails, even if both appears to be the same string.

    Let me write down the actual code that I wrote just to check if the if test works (and it doesn't):

    $mycategory = get_the_term_list( $post_id, 'portfolio_category', '', ', ', '' ) ;
    echo $mycategory ; // output is portrait !!!!
    If ($mycategory == "portrait") { echo " correct"  ; }
    else { echo " it fails" ; }

    The result is "it fails"
    That is: on the screen, $mycategory appears to be "portrait" as expected, but the comparation with string "portrait" fails.

    It's getting me crazy.

    Any help ?

    Tks.

    [Please post code snippets between backticks or use the code button.]

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Returns an HTML string of taxonomy terms associated with a post and given taxonomy. Terms are linked to their respective term listing pages.

    http://codex.wordpress.org/Function_Reference/get_the_term_list

    The bold is mine. :-)

  3. pikkabbu
    Member
    Posted 2 years ago #

    Thanks Esmi.

    In fact, I'm in the same situation than before :-(

    that is: How do I compare a.... html string to a text string ?

    I guess there is any converting function, something like

    $mytruecategory = convertion($myhtmlcategory) but I can't find it out.

    I've seen a lot of convertions, but I don't understand what they do and which to use.

    Still need some help.

    Yhank you

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    How do I compare a.... html string to a text string

    If it was me, the first thing I'd do is examine exactly what $mycategory holds by using

    echo '<pre>';
    print_r($mycategory);
    echo '</pre>';

    and if necessary, checking the source code of the output for any HTML tags. Then use strip_tags() to remove any HTML tags from the returned value(s) and, if necessary, trim() to ensure that I was comparing like with like.

  5. pikkabbu
    Member
    Posted 2 years ago #

    Thank you very much for your quick answer !!

    Now I'm going to work the way you say.

    I'll get back here and tell how I manage ;-)

    But... it's 1 o'clock in the morning, and my eyes are saying "pleeeeaaaase stop".

    I'll have to way until tomorrow.

  6. pikkabbu
    Member
    Posted 2 years ago #

    I couldn't wait !

    I just wanted to check your code and...
    discovered that $mycategory had more than only letters.

    This has been important !

    Afterwards, I tried strip_tags and ta tchannnn : it works, and now my if test works too.

    Solved problem.

    Thanks so much !!!
    I can now go and sleep happy.

  7. esmi
    Forum Moderator
    Posted 2 years ago #

    Yay! Glad I could help :-)

Topic Closed

This topic has been closed to new replies.

About this Topic