3w PHP Your Source for PHP Source Code

11Nov/101

Function to check if a string exist in another string

Option 1
We call for the position of the string, if it dose not exist, we get FALSE, which is what we check for in option 1.

<?php
function match_str_part($main_str , $needle)
{
	if (empty($main_str) || empty($needle))
	{
		return false;
	}
 
	if (strpos($main_str , $needle) !== FALSE)
	{
		return true;
	}
	return false;
}
?>

Option 2
Simply checking if the string exist as part of another.

<?php
function match_str_part($main_str , $needle)
{
	if (empty($main_str) || empty($needle))
	{
		return false;
	}
 
	if (strstr($main_str , $needle))
	{
		return true;
	}
	return false;
}
?>
Filed under: PHP Functions 1 Comment
11Nov/102

Function to get UNIX time

This will return a UNIX style time stamp...

<?php
function get_unix_time()
{
	return time();
}
?>
Filed under: PHP Functions 2 Comments