Question

I'm working on a project of Bulk sms, In india for transactional route you should register a template with Telecom operator.

Now how we identify the user sending the same template or other one ?

I did some research and written some code like below.

$txt1 = "TXN: <452235585> was Failed. Reference no. <452525222>";
$txt2 = "TXN: 452235585 was Failed. Reference no. 452525222. Geeglobia providing best holiday packages. Check it now";

similar_text(ltrim($txt1, '0123456789'), ltrim($txt2, '0123456789'), $percent);

echo $percent; // Gives 63.694267515924

Can any one gives a better idea ?

Was it helpful?

Solution

Actually the most convinient way to do this is by using regular expressions. There are two alternatives:

1) Do not specify the first string as a string but as a regexp-pattern instead, use preg_match to compare:

$txt1 = '/^TXN: .*? was Failed. Reference no. .*?$/';
$txt2 = "TXN: 452235585 was Failed. Reference no. 452525222. Geeglobia providing best holiday packages. Check it now";

$match = (preg_match($txt1, $txt2) == 1);

2) Convert the first string to a pattern, then do as above.

$txt1 = "TXN: <452235585> was Failed. Reference no. <452525222>";
$txt2 = "TXN: 452235585 was Failed. Reference no. 452525222. Geeglobia providing best holiday packages. Check it now";

$convertedTxt1 = '/^' . preg_replace("/(.*?)<.*?>/", "$1.*?", $txt1) . '$/';

$match = (preg_match($convertedTxt1, $txt2) == 1);

(code snippets untested)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top