echo strcmp("Hello world","HELLO WORLD"); // Output is 1
Output is equal to
$str1="Hello World";
$str2="hello world";
echo strcmp($str1,$str2); // Output is -1
echo "<br>";
if(strcmp($str1,$str2)==0){
echo "Both strings are matching";
}else{
echo "Both strings are different ";
}
Output is
-1
Both strings are different
Example 2
$str1="Hello World";
$str2="Hello World";
echo strcmp($str1,$str2); // Output is 0
echo "<br>";
if(strcmp($str1,$str2)==0){
echo "Both strings are matching";
}else{
echo "Both strings are different ";
}
Output is here
0
Both strings are matching
$result = strcasecmp('Hello', 'hello');
if ($result === 0) {
echo 'The strings are equal (case-insensitive).';
} else {
echo 'The strings are not equal.';
}
Output
The strings are equal (case-insensitive).
$str1 = mb_convert_encoding('Straße', 'UTF-8', 'ISO-8859-1');
$str2 = 'Strasse';
if (strcmp($str1, $str2) === 0) {
echo "The strings are equal.";
} else {
echo "The strings are not equal.";
}
Output
The strings are not equal.
These examples improve the depth of string comparison by considering case insensitivity and encoding differences.
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.