Dvdrw
Dvdrw

Reputation: 37

php - compare two strings

I have this part of PHP code:

<?php
$dns = file_get_contents('./dns.txt');

$dns2 = 'serverquery://name:[email protected]:10011/?server_port=9987&use_offline_as_virtual=1&no_query_clients=1';

$dns3 = 'serverquery://name:pass@' . $dns . ':10011/?server_port=9987&use_offline_as_virtual=1&no_query_clients=1';

if (strcmp($dns2, $dns3) !== 0) {
    echo '$dns2 is not equal to $dns3';
}

echo '<br><br>DNS<br>';
print $dns;
echo '<br><br>DNS2<br>';
print $dns2;
echo '<br><br>DNS3<br>';
print $dns3;
echo '<br><br><br>';

?>

file dns.txt contais only text example.com without any space at the begin or at the end

when I run this code, the result is:

$dns2 is not equal to $dns3

DNS
example.com

DNS2
serverquery://name:[email protected]:10011/?server_port=9987&use_offline_as_virtual=1&no_query_clients=1

DNS3
serverquery://name:pass@example.com:10011/?server_port=9987&use_offline_as_virtual=1&no_query_clients=1

i'm trying to create serverquery for TeamSpeak 3 server and it only works if I use $dns2 and I want it to work with $dns3

so my question is: why $dns2 is not equal to $dns3 ?

can you please help me ?

Upvotes: 1

Views: 102

Answers (1)

Frederik Krautwald
Frederik Krautwald

Reputation: 1860

You have some hidden characters in your dns.txt file. Make sure it is encoded UTF-8 without BOM.

The UTF-8 BOM is a sequence of bytes (EF BB BF), hence the overhead of three characters.

Upvotes: 1

Related Questions