I Found some code in stacke overflow is error .
- function is_found(p) is ok
- function is_found2(p) from stack overflow is fail !
- ref: (http://stackoverflow.com/questions/21729960/how-do-i-use-syntax-highlighting-in-php-within-a-markdown-github-gist)
- you can test this code by paste to page (http://phptester.net/)
<?php
echo "<h1>Test strpost() PHP </h1>";
$a_test = ['as', 'x111','ab' , 'd a', 'ab' , ' ab'];
$a_expect = ["f", "nf" , "f" , "f" , "f" ,"f"];
$a = "asfasv xxda ssd abab fs";
echo "<h2>p = strpos(haystack, needle ) </h2>" ;
echo "<table border=1 width='80%'><tr>"
."<td colspan=10 width= > Search in string haystack:<b>'$a'</b> </td></tr>";
echo "<tr bgcolor='lightyellow'><td>needle </td><td>Expect</td>"
. "<td>is_int?</td><td>isBool?</td>"
."<td>isset?</td><td>empty?</td><td>is0?</td><td>p=</td>"
. "<td>is_found(p)?</td><td>is_found2 </td></tr>";
foreach($a_test as $idx => $test1 ){
$p = strpos($a , $test1 );
echo "<tr>";
echo "<td bgcolor='lightyellow'>$test1</td>";
echo "<td>" . ($a_expect[$idx] == "f" ?"E.Found":"E.Not_Found")
. "</td>";
echo "<td>" . (is_int($p)?"is_int(p)":"!is_int(p)") . "</td>";
echo "<td>" . (is_bool($p)?"is_bool(p)":"!is_bool(p)") . "</td>";
echo "<td>" . (isset($p)?"isset(p)":"!isset(p)") . "</td>";
echo "<td>" . (empty($p)?"empty(p)":"!empty(p)") . "</td>";
echo "<td>" .($p== 0?"p==0":"p!=0") ."</td>";
echo "<td>$p </td>" ;
echo "<td>" . (is_found($p)? "True" : "-") ."</td>";
echo "<td>" . (is_found2($p)? "True" : "-") ."</td>";
echo "</tr>" ;
}
echo "</table>" ;
function is_found($p){
return ($p==0&&is_int($p))||($p!=0) ;
}
// This is Error !!!
// from stackoverflow but error
// http://stackoverflow.com/questions/4366730
// /how-do-i-check-if-a-string-contains-a-specific-word-in-php
function is_found2($p){
return ($p != false );
}
echo "<br>Note: function <b>is_found(p)</b> == (p==0&&is_int(p))||(p!=0) ";
?>