Skip to content

Instantly share code, notes, and snippets.

@tps2015gh
Last active February 9, 2017 07:05
Show Gist options
  • Save tps2015gh/c4e9d47a9959a7cbe30434a5f1f817cb to your computer and use it in GitHub Desktop.
Save tps2015gh/c4e9d47a9959a7cbe30434a5f1f817cb to your computer and use it in GitHub Desktop.

I Found some code in stacke overflow is error .

<?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) ";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment