I'm trying to take 2 versions of text (10 pages long) and compare the 2 to produce the difference. I know Wikipedia has a similar feature to compare revisions. Does anyone know what they use? I'm hoping they're using a php-driven solution.
There is an implimentation of diff in php. I haven't used it but it's a start. There is also something called PHP inline diff that you can check out
Related
I have to show difference between two sentence or paragraph. It can be any thing.
Same like in this site original question and edited question.
for example I love apple original sentence. and edited sentence is I do not love banana, I need is: do not and banana here. different from original.
How can I do this in PHP?
What you're asking about is called the Longest common subsequence problem, which is a dynamic algorithm that's typically the basis of comparison utilities like a diff utility (also like those you see in svn or git, for example).
Luckily PHP has a massive PECL repository with an xdiff extension with just such functions already available for you, such as xdiff_string_diff
Here nice Lib you can use it
finediff.php
http://www.raymondhill.net/finediff/finediff-code.php
your-file.php
include 'finediff.php';
$opcodes = FineDiff::getDiffOpcodes($original, $edited);
I am trying to store some data locally in a database.
Now every time I change my articles, I want to know how many lines got added, and how many got deleted?
Kind of like:
Is there an easy where were I compare the $old_string vs $new_string, and work out the difference in PHP?
You probably want to use xdiff_string_diff with setting $context to 0 and check the output. Check the php manual
Quick embrassing question.
I have been looking for a PHP function that would calculate the difference between two timestamps and output the result based on given parameters such as
the diff in years only, diff in months only, diff in days only, etc etc
The function I made has been quite buggy and I haven't found a good one on the Net.
Please assist.
Thanks
Please take a look at DateTime::diff()
DateTime::diff — Returns the difference between two DateTime objects
You can format the output to anything you want it to be
(Provided an extra answer despite of the duplicates because they use strtotime & math and that doesn't always work out well or is a nice way to do it. Using a core function of php seems nicer to me)
I want to show when the comment last posted in PHP. like 5 minutes ago, 2 days ago, 7 weeks ago. How to do this?
You can find plenty of answers with full solutions in different languages, pseudocode, ideas, etc.. here.
I believe there's an example of PHP too.
You can use timeago, a jQuery plugin, to do it via Javascript. It would yield the same result, update without refreshing, and by doing it client side instead of server side, you are not precluded from caching.
http://timeago.yarp.com/
Otherwise, Annurag has a link with some good PHP solutions.
You can do manual calculation in server, to get the time difference, then translate it into human time format.
Or my preference, do it in browser using javascript. Using this approach, the time in page can be updated without refresing the page.
You can use this jQuery EasyDate library to translate a DOM element into humane time format.
You can also read the comments in this post about Pretty Date by John Resig. It contain the code, and improvement by other.
Store the comment posted in the date DB and show the the same in the front end by comparing with current date and time using php function
I have this code template in Eclipse
#since ${date}
when entered i get something like this :
#since 4.8.2009
But when i add the same template (#since ${date}) to NetBeans
it outputs
#since date
Can someone help ?
No answer yet ? Is this not possible in Netbeans ???
Something like the following example should doing the job :
${date?date?string("yyyy")}.${date?date?string("MM")}.${date?date?string("dd")}
yyyy => year on 4 elements (ex: 2012)
MM => Month on 2 elements (ex: march -> 03)
dd => Day of the month on 2 elements (ex: 23)
. => separator you want to separate each fields (ex: - or / or . or smth else)
You should have to check about available format somewhere in the netbeans help (sorry I don't find out informations about this for now).
I see that's a very old post, but if it may usefull for someone ...
regards.
ollie314
Not wanting to raise the dead with this post, but I thought it worth mentioning so I signed up to SO specifically to clarify, since Ollie314 saved me a lot of time.
The format ollie314 used is correct (for version 7.1+ at least) BUT just to be clear, if it's not displaying correctly it may be due to your system locale settings, if outside of USA. Be sure to include <#setting locale="en_AU"> (replace en_AU with your locale id) in the template you are editing, prior to the date?date?string cast declaration, or it will not work. If you place it in the user settings it won't cast the date string in the template and you will generate errors in your template output.
The documentation from Netbeans isn't particularly clear on that. Still, best IDE ever :)
Inserting ${date?date?string("yyyy")} within your template will do the trick (if you want year only)
Note: With NetBeans 6.5/6.7, if you do not find that template, you could create it.
See this tutorial.
I'm pretty sure this is not possible in Netbeans, or at least not worth the amount of trouble. It's possible that you could author your own Netbeans module, add a code template to the module (in which you might be able to put the ${date} as an extra variable, I'm not sure), and then add the module to Netbeans. But you could also just type the date in, which, unless you type it several thousand times per day, would probably take less time.
Your snippet looks like freemarker code. This is used in Netbeans for file templates (Tools -> Templates). If you put ${date} in a file template it will get transformed when the file is created to the current date. If you're trying to use it as a code template I don't know how that works.
Even simpler, use ${date?date?string.yyyy}