php - StrPos always returns False? -
i've been working on basic search engine. operates checking if word exists. if does, returns link. know of suggest create database phpmyadmin don't remember password make mysql_connect
command work.
anyway here code:
<?php session_start(); $searchinput = $_post['search']; var_dump($inputpage1); var_dump($searchÄ°nput); $inputpage1 = $_session['ponetext']; $inputpage2 = isset($_session['ptwotext']) ? $_session['ptwotext'] : ""; $inputpage3 = isset($_session['pthreetext']) ? $_session['pthreetext'] : ""; if (strpos($inputpage1, $searchinput)) { echo "true"; } else { echo "false"; } ?>
when search word, word page, weather exists or not, returns false. know why?
from php documentation:
warning: function may return boolean false, may return non-boolean value evaluates false. please read section on booleans more information. use === operator testing return value of function.
so function returns integer 0
since $searchinput
starts @ first character of $inputpage1
. since inside if condition, expects boolean, integer converted one. when converted boolean, 0 equal false instead else block executed.
to fix it, need use !==
operator (the not equal equivalent of ===
):
if (strpos($inputpage1, $searchinput) !== false) { //...
Comments
Post a Comment