 
 // MARK: - global PHP Style String functions
 
-struct PString {
+public struct PString {
 
-    static func strtoupper(string: String) -> String {
+    public static func strtoupper(string: String) -> String {
         return string.uppercaseString
     }
 
-    static func strtolower(string: String) -> String {
+    public static func strtolower(string: String) -> String {
         return string.lowercaseString
     }
 
-    static func substr(string: String, _ start: Int) -> String? {
+    public static func substr(string: String, _ start: Int) -> String? {
         if(start>0) {
             return substr(string, start, string.characters.count)
         } else {
             return substr(string, string.characters.count+start, string.characters.count)
         }
     }
+
+    public static func ltrim(string: String, characterSet: NSCharacterSet=NSCharacterSet.whitespaceAndNewlineCharacterSet()) -> String {
+        if let range = string.rangeOfCharacterFromSet(characterSet.invertedSet) {
+            return string[range.startIndex..<string.endIndex]
+        }
+        return string
+
+    }
+
+
+    public static func rtrim(string: String, characterSet: NSCharacterSet=NSCharacterSet.whitespaceAndNewlineCharacterSet()) -> String {
+        if let range = string.rangeOfCharacterFromSet(characterSet.invertedSet, options: NSStringCompareOptions.BackwardsSearch) {
+            return string[string.startIndex...range.startIndex]
+        }
+        return string
+    }
+
+
 
     /**
      Returns a sub string


    static let PREG_OFFSET_CAPTURE=1

    static func preg_match(pattern: String, _ subject: String, inout _ matches: [String], _ flags: Int = 0, _ offset: Int = 0) -> Int {
        if let subjectWithOffset=substr(subject, offset, strlen(subject)) {
            if subjectWithOffset.isMatching(pattern) {
                return 1
            }
        }
        return 0
    }

    static func preg_replace (pattern: String, _ replacement: String, _ subject: String, _ limit: Int = -1) -> String {
        do {
            let regex = try NSRegularExpression(pattern: pattern, options: [.CaseInsensitive])
            return regex.stringByReplacingMatchesInString(subject, options: [], range: NSMakeRange(0, strlen(subject)), withTemplate:replacement)


     - returns: the sub string
     */
    public static func substr(string: String, _ start: Int, _ length: Int) -> String {
        let startIndex: String.Index?
        if start<0 {
            let l=strlen(string)
