Show DevBest [PHP] Contains function [Mac Product]

Status
Not open for further replies.

Mac

New Member
Feb 9, 2011
111
2
PHP:
<?php
function contains( $a, $b, $c ) {	
	if(isset($a, $b, $c)):
		if( $c == '1' ):
			return preg_match( "/" . $a . "/", $b );
		else:
			return preg_match( "/" . $a . "/i", $b );
		endif;
	else:
		throw new exception('Required fields for this function are not set!');
	endif;
} 
echo ( contains( $_GET['p1'], $_GET['p2'], $_GET['case'] ) ? "Yes!" : "No!" );
?>

Credits to me for the base and m0nsta. for editing!
 

Mac

New Member
Feb 9, 2011
111
2
Thanks both ! I will release more of my scripts tomoz .
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Just a slightly improved version:

PHP:
<?php
function contains( $a, $b, $c )
{
	if( $c == '1' )
	{
		return preg_match( "/" . $a . "/", $b );
	}
	else
	{
		return preg_match( "/" . $a . "/i", $b );
	}
} 
echo ( contains( $_GET['p1'], $_GET['p2'], $_GET['case'] ) ? "Yes!" : "No!" );
?>

It gets the strings from the URL and checks if it is case sensitive

will return: "Yes!"
will return: "No!"

Code:
case=0 in the URL means that it is not case sensitive
Code:
case=1 in the URL means that it is case sensitive
 

Mac

New Member
Feb 9, 2011
111
2
Oh that's very good idea! Thanks!

edit: i edited your code abit and put in the first post! check it out!
 
Status
Not open for further replies.

Users who are viewing this thread

Top