Are there any libraries (3rd party or built-in) in PHP to calculate text diffs?
it depends exactly what you mean and what you want to do but there is
PEAR Text_Diff - Engine for performing and rendering text diffs
What sort of diffs? File diffs? There is array_diff() which acts on arrays. Then there is also xdiff, which "enables you to create and apply patch files containing differences between different revisions of files.". The latter acts on files or strings.
Edit: I should add xdiff doesn't appear to be out in a release yet. You have to build from source to use it.
It really depends on what outcome you want. If all you want to do is to get the diff files for two sets of text, you may find it simpler to just use an external diff command (which of course totally depends on the environment you're developing for).
$diff = `diff $file1 $file2`;
From there if you want to use the diff information at all you would need to parse and this solution might not be what you're after. In that case I'd suggest looking at the PEAR library mentioned above or searching for a similar text parsing library.
MediaWiki's diff engine is open source (just like the rest of it). If you like the way Wikipedia handles text diffs, it may be a solution for you.
There is a nice and tiny Simplediff project on Github which creates text and HTML diffs.