Title: Comparing strings doesn&#039;t work !?!?
Last modified: August 20, 2016

---

# Comparing strings doesn't work !?!?

 *  Resolved [pikkabbu](https://wordpress.org/support/users/pikkabbu/)
 * (@pikkabbu)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/comparing-strings-doesnt-work/)
 * 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.]_

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/comparing-strings-doesnt-work/#post-2368698)
 * > 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](http://codex.wordpress.org/Function_Reference/get_the_term_list)
 * The bold is mine. 🙂
 *  Thread Starter [pikkabbu](https://wordpress.org/support/users/pikkabbu/)
 * (@pikkabbu)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/comparing-strings-doesnt-work/#post-2368708)
 * 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
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/comparing-strings-doesnt-work/#post-2368709)
 * > 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()](http://php.net/manual/en/function.strip-tags.php) to remove
   any HTML tags from the returned value(s) and, if necessary, [trim()](http://uk.php.net/manual/en/function.trim.php)
   to ensure that I was comparing like with like.
 *  Thread Starter [pikkabbu](https://wordpress.org/support/users/pikkabbu/)
 * (@pikkabbu)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/comparing-strings-doesnt-work/#post-2368715)
 * 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.
 *  Thread Starter [pikkabbu](https://wordpress.org/support/users/pikkabbu/)
 * (@pikkabbu)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/comparing-strings-doesnt-work/#post-2368738)
 * 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.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/comparing-strings-doesnt-work/#post-2368742)
 * Yay! Glad I could help 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Comparing strings doesn't work !?!?’ is closed to new replies.

## Tags

 * [get_the_term_list](https://wordpress.org/support/topic-tag/get_the_term_list/)

 * In: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
 * 6 replies
 * 2 participants
 * Last reply from: [esmi](https://wordpress.org/support/users/esmi/)
 * Last activity: [14 years, 7 months ago](https://wordpress.org/support/topic/comparing-strings-doesnt-work/#post-2368742)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
