Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making my own STRPOS function.

Status
Not open for further replies.

748323

Programmer
Dec 10, 2004
70
US
Honestly, I hate PHP's STRPOS. I never seem to remember how to use it, unless I look it up on php.net. I decided to make my own function to check if one string is present in another. Other than slower loading times, is there anything bad about using my custom function? Thanks.

Code:
<?

function aisinb($string, $string2) {
	$string2_copy = $string2;
	$string2_copy = str_replace($string, "", $string2_copy);
	if ($string2 != $string2_copy) {
		return TRUE;
	} else {
		return FALSE;
	}
}

?>
 
Correct me if I'm mistaken, but does your function not only return TRUE or FALSE?

strPOS, returns the POSition of the STRing.

Olav Alexander Mjelde
Admin & Webmaster
 
I know, but STRPOS will return true if one string appears in another. That's what I'm trying to duplicate.
 
Returns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos(), this function can take a full string as the needle parameter and the entire string will be used.

This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

I dont think you quite get what you use the strpos function for.

ref.:
Olav Alexander Mjelde
Admin & Webmaster
 
Have you considered using stristr() instead?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top