Checking if string appears in content.
-
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');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Checking if string appears in content.’ is closed to new replies.