• Resolved Snaphaan

    (@snaphaan)


    It seems comparing two exact same strings in the widget display function does not result in true. I have saved the word ‘test’ in the textarea so the code below should result in displaying something like:

    correct: test

    But it always throws out false which means that the $textarea string value from the widget somehow differs from a normally assigned string.

    I’ve tried a normal string comparison as well:

    if($textarea == "test")

    … and it still results as false.

    Any ideas?

    function widget($args, $instance) {
    	extract($args);
    	$title = apply_filters('widget_title', $instance['title']);
    	$text = $instance['text'];
    	$textarea = $instance['textarea'];
    	$block = "test";
    
    if(strcmp($textarea, $block) == 0) {
    	echo '<p class="wp_widget_plugin_textarea">correct: '.$textarea.'</p>';
    	} else {
    	echo 'False';
    	}
    
            echo '</div>';
            echo $after_widget;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Snaphaan

    (@snaphaan)

    Apologies for the typo:
    if(strcmp($textarea, $block) == 0) should actually be:
    if(strcmp($textarea, $block) == 1) as being true.

    Thread Starter Snaphaan

    (@snaphaan)

    Somehow it’s working now. There’s probably some difference on how I store the data and what I want to retrieve.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Widget: cannot compare exact same strings’ is closed to new replies.