View Single Post
Old 05-23-2008, 04:00 PM   #1 (permalink)
Jelmer
The Wanderer
 
Join Date: Dec 2007
Location: The Netherlands
Posts: 13
Thanks: 3
Jelmer is on a distinguished road
Confused Strange string comparison problem

I'm making some changes to my site, which is based on vbulletin and some things I made had to be fixed after upgrading vbulletin. I use categories to display some content using an url like this:

So to get the content I need to get the ID associated with that category, it seems simple but when I check if the category exists I run into a problem. I do this by checking if the entered category name is the same as one of the categories from the existing array of categories.

Both strings seem to be the same but the length is different.. Here's some var_dump() from the code:

I've tried various things to "fix" the length of the string using trim() and strlen() but that didn't work.. When I use strlen() to shorten the longer string, nothing remains of it.. here's the code and var_dump:
PHP Code:
$forum_categories fetch_prefix_html 17 );
    
$category_array explode "\n"$forum_categories );
    
$category_array array_filter $category_array );
    
//clean up category array
    
function trim_value(&$value
    {
        
$value trim $value );
    }
    
array_walk $category_array'trim_value' );
    
    
var_dump($category);
    
var_dump($category_array[4]);
    
var_dump strlen($category) );
    
var_dump strlen($category_array[4]) );
    
var_dump($category == $category_array[4]);
    
$category_array_fix substr($category_array[4], 0strlen($category));
    
$category_array_trim trim($category_array[4]);
    
var_dump($category_array_trim);
    
var_dump($category_array_fix); 
Code:
string(11) "compositing" string(52) "compositing" int(11) int(52) bool(false) string(52) "compositing" string(11) "
I hope you can help me out, I'm getting kind of frustrated, it seems a very simple and silly problem but I don't understand what's wrong..
Jelmer is offline  
Reply With Quote