Forums

Checking if string appears in content. (2 posts)

  1. oliverhelm
    Member
    Posted 1 year ago #

    Hi,

    Im trying to determine weather or not a string appears within the content. The aim is to right a function i can call to check this, returning a simple true or false. I've been trying to do this with the bellow code, but i always get the response ($dResponce) returned as true.

    I've tested the "if ($test === false) {..." bit and it works fine, but it is not setting the value of dataResponce(). If i put echo's in that part the right answer is displayed.

    My code is pasted bellow. Any suggestions would be greatly appreciated.

    Many Thanks.

    function dataResponce($dResponce) {
    			if ($dResponce = true) {
    				echo "true";
    			}
    			elseif ($dResponce = false) {
    				echo "false";
    			}
    		}
    
    		function in_this_instance($data) {
    			$rep_val = '[front banner]';
    			$test = strpos($data, $rep_val);
    			if ($test === false) {
    				dataResponce(false);
    			}
    			else {
    				dataResponce(true);
    			}
    			return $data;
    		}
    
    add_filter('the_content', 'in_this_instance');
  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    try to use double == in the if statements:

    function dataResponce($dResponce) {
    			if ($dResponce == true) {
    				echo "true";
    			}
    			elseif ($dResponce == false) {
    				echo "false";
    			}
    		}

Topic Closed

This topic has been closed to new replies.

About this Topic