File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings / strncmp_basic.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:04 2012 UTC (12 years, 5 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, v5_3_10, HEAD
php

--TEST--
Test strncmp() function : basic functionality 
--FILE--
<?php
/* Prototype  : int strncmp ( string $str1, string $str2, int $len );
 * Description: Binary safe case-sensitive string comparison of the first n characters
 * Source code: Zend/zend_builtin_functions.c
*/

echo "*** Testing strncmp() function: basic functionality ***\n";

echo "-- Testing strncmp() with single quoted string --\n";
var_dump( strncmp('Hello', 'Hello', 5) );  //expected: int(0)
var_dump( strncmp('Hello', 'Hi', 5) );  //expected: value < 0
var_dump( strncmp('Hi', 'Hello', 5) );  //expected: value > 0

echo "-- Testing strncmp() with double quoted string --\n";
var_dump( strncmp("Hello", "Hello", 5) );  //expected: int(0)
var_dump( strncmp("Hello", "Hi", 5) );  //expected: value < 0
var_dump( strncmp("Hi", "Hello", 5) );  //expected: value > 0

echo "-- Testing strncmp() with here-doc string --\n";
$str = <<<HEREDOC
Hello
HEREDOC;
var_dump( strncmp($str, "Hello", 5) );  //expected: int(0)
var_dump( strncmp($str, "Hi", 5) );  //expected: value < 0
var_dump( strncmp("Hi", $str, 5) );  //expected: value > 0

echo "*** Done ***";
?>
--EXPECTREGEX--
\*\*\* Testing strncmp\(\) function: basic functionality \*\*\*
-- Testing strncmp\(\) with single quoted string --
int\(0\)
int\(-[1-9][0-9]*\)
int\([1-9][0-9]*\)
-- Testing strncmp\(\) with double quoted string --
int\(0\)
int\(-[1-9][0-9]*\)
int\([1-9][0-9]*\)
-- Testing strncmp\(\) with here-doc string --
int\(0\)
int\(-[1-9][0-9]*\)
int\([1-9][0-9]*\)
\*\*\* Done \*\*\*

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>