diff includes/class.textutils.php @ 0:629389204276

Import initial
author Franck Deroche <webmaster@defr.org>
date Sat, 20 Oct 2007 14:15:10 +0200
parents
children 8f1125d27079
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/includes/class.textutils.php	Sat Oct 20 14:15:10 2007 +0200
@@ -0,0 +1,30 @@
+<?php
+    class TextUtils
+    {
+	public static function SplitTags($str)
+	{
+	    $str = str_replace("\\\"", "\"", $str);
+	    $tags = array();
+	    preg_match_all('/"([a-zA-Z0-9 ]+)"/', $str, $tests);
+	    $useful = $tests[1];
+	    foreach($useful as $match)
+	    {
+		$tags[] = $match;
+		$str = str_replace("\"{$match}\"", null, $str);
+	    }
+	    $str = preg_replace("/( )+/", " ", trim($str));
+	    if(strlen($str) > 0)
+		$tags = array_merge($tags, explode(" ", $str));
+	    asort($tags);
+	    return $tags;
+	}
+	
+	public static function DiffTagLine($old, $new, &$ajout, &$suppr)
+	{
+	    $arOld = TextUtils::SplitTags($old);
+	    $arNew = TextUtils::SplitTags($new);
+	    $ajout = array_diff($arNew, $arOld);
+	    $suppr = array_diff($arOld, $arNew);
+	}
+    }
+?>
\ No newline at end of file