how string comparison is done in php?
i wan to copmpare two strings and result i want is the same letters in both strings?
any help plz

The strcmp() function is binary safe and case-sensitive.

Example

<?php
echo strcmp("Hello world!","Hello world!");
?>

The output of the code above will be:
0

Member Avatar for diafol

SO you want something like this?

Text1: Hello World
Text2: Hi words are my music

Hits: H,e,o,r,d

Do you need case-sensitivity or extended characters?

yes i want this with case sensitivity

Member Avatar for diafol
$text1 = "Hello this is!!! my time";
$text2 = "ThiHs is unbelievables";

$r1 = str_split(preg_replace("/[^a-zA-z]/","",$text1)); //make array of alphabetical chars only
$r2 = str_split(preg_replace("/[^a-zA-z]/","",$text2)); //ditto
$hits =array_unique(array_intersect($r1,$r2)); //get an array of common chars
sort($hits); //sort chars
$hits = implode(", ",$hits); //create a comma delimited list of chars
echo "Matches for \"$text1\" and \"$text2\" are: $hits"; //echo output

Maybe an easier method though.

thanku so much ardav :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.