Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Compare Two Strings with strcmp()
How To Compare Two Strings with strcmp()? - PHP Script Tips - PHP Built-in Functions for Strings
✍: FYIcenter.com
PHP supports 3 string comparison operators, <, ==, and >, that generates Boolean values. But if you want to get an integer result by comparing two strings, you can the strcmp() function, which compares two strings based on ASCII values of their characters. Here is a PHP script on how to use strcmp():
<?php $a = "PHP is a scripting language."; $b = "PHP is a general-purpose language."; print('strcmp($a, $b): '.strcmp($a, $b)."\n"); print('strcmp($b, $a): '.strcmp($b, $a)."\n"); print('strcmp($a, $a): '.strcmp($a, $a)."\n"); ?>
This script will print:
strcmp($a, $b): 1 strcmp($b, $a): -1 strcmp($a, $a): 0
As you can see, strcmp() returns 3 possible values:
2007-04-21, 7655👍, 0💬
Popular Posts:
How To Dump the Contents of a Directory into an Array? - PHP Script Tips - Working with Directoris a...
What are the two kinds of comments in JSP and what's the difference between them? <%-- JSP Co...
How To Set session.gc_maxlifetime Properly? - PHP Script Tips - Understanding and Using Sessions As ...
How To Empty Your Recycle Bin? - Oracle DBA FAQ - Managing Oracle Database Tables If your recycle bi...
What is the concept of XPOINTER? XPOINTER is used to locate data within XML document. XPOINTER can p...