You are here: Re: [PHP] comparing two texts « PHP « IT news, forums, messages
Re: [PHP] comparing two texts

Posted by JamesBenson on 06/20/05 12:01

I saw a function in the php manual the other day which displays the
difference as a percentage, for instance two strings,

foo
foos

would be maybe 90% match, not sure thats what you mean though, you can
always do a str_replace like so,


$string1 = 'foo';
$string2 = 'foos';


$string = (str_replace("$string1", "", $string2));

echo "$string";


The difference being one letter in this case, the letter 's', whether
that would work for what your after im not sure because it would depend
on string1 containg string in the same order but not work for random
characters.




jenny mathew wrote:
> so,what what should i conclude .it is not possible to compare two texts and
> hight the difference at this moment.
> thanks.
> Yours ,
> Jenny
>
> On 6/19/05, Robert Cummings <robert@interjinn.com> wrote:
>
>>On Sun, 2005-06-19 at 12:33, M. Sokolewicz wrote:
>>
>>>Robert Cummings wrote:
>>>
>>>>On Sun, 2005-06-19 at 09:22, M. Sokolewicz wrote:
>>>>
>>>>
>>>>>jenny mathew wrote:
>>>>>
>>>>>
>>>>>>>Untested, very crude:
>>>>>>>
>>>>>>><?php
>>>>>>>$maxlen = max(strlen($text1), strlen($text2));
>>>>>>>for ($i = 0; $i < $maxlen; $i++){
>>>>>>>if (@$text1[$i] == @$text2[$i]) echo @$text1[$i];
>>>>>>>else @echo "<font color=red>$text1[$i]|$text2[$i]</font>";
>>>>>>>}
>>>>>>>?>
>>>>>>
>>>>>>donot you think you program will just bring the server to its foot
>>
>>,if the
>>
>>>>>>text message encountered is very large of order of 40 KB or
>>>>>>larger.is <http://larger.is><http://larger.is>there any other
>>
>>efficient method.
>>
>>>>>40KB isn't large... now, when you're talking about hundreds of MBs of
>>>>>text, then it gets large :) 40KB, with that method, is nothing...
>>>>
>>>>
>>>>It's a bit of a dirty hack though. If I compare a 2 character text
>>>>against a 40k text, the error handler will be invoked (39998 * 3)
>>
>>times
>>
>>>>if $text1 is the 2 byte string. That's extremely inefficient. I don't
>>>>think I've ever seen error suppression abused so badly to prevent
>>>>writing an extra line or 2 using isset().
>>>>
>>>>Cheers,
>>>>Rob.
>>>
>>>I agree with what you said fully; however, even though that's the case,
>>>and it indeed could be written a lot faster and cleaner, it would not
>>>pose a problem on most systems. That was the point I tried to make ;)
>>
>>Oh absolutely, 40k is tiny :) Just never seen error suppression used for
>>such mundane processing. Now if we up it to 2 chars and 5 megs :) With a
>>custom user space error handler in the background... ugh.
>>
>>Cheers,
>>Rob.
>>--
>>.------------------------------------------------------------.
>>| InterJinn Application Framework - http://www.interjinn.com |
>>:------------------------------------------------------------:
>>| An application and templating framework for PHP. Boasting |
>>| a powerful, scalable system for accessing system services |
>>| such as forms, properties, sessions, and caches. InterJinn |
>>| also provides an extremely flexible architecture for |
>>| creating re-usable components quickly and easily. |
>>`------------------------------------------------------------'
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация