How to compare strings in PHP

4 Answers

0 votes
$s1 = "php";
$s2 = "java";

if ($s1 == $s2) {
    echo 'Match';
} else {
    echo 'Not match';
}



/*
run:

Not match

*/

 



answered Aug 12, 2020 by avibootz
0 votes
<?php

$s1 = "php";
$s2 = "PHP";

if ($s1 == $s2) {
    echo 'Match';
} else {
    echo 'Not match';
}



/*
run:

Not match

*/

 



answered Aug 12, 2020 by avibootz
0 votes
$s1 = "php";
$s2 = "PHP";

if (strcmp($s1, $s2) == 0) {
    echo 'Match';
} else {
    echo 'Not match';
}



/*
run:

Not match

*/

 



answered Aug 12, 2020 by avibootz
0 votes
$s1 = "php";
$s2 = "PHP";

if (strcasecmp($s1, $s2) == 0) {
    echo 'Match';
} else {
    echo 'Not match';
}



/*
run:

Match

*/

 



answered Aug 12, 2020 by avibootz

Related questions

1 answer 102 views
102 views asked Jun 15, 2022 by avibootz
1 answer 249 views
4 answers 410 views
1 answer 68 views
1 answer 117 views
...