 
 // 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 func preg_replace (pattern: String, _ replacement: String, _ subject: [String], _ limit: Int = -1) -> [String] {
        var r=[String]()
        for subSubject in subject {
            r.append(preg_replace(pattern, replacement, subSubject, limit))

        return string.substringWithRange(startIndex! ..< endIndex)
    }

    public static func strlen(string: String) -> Int {
        return string.characters.count
    }

    public static func lcfirst(string: String) -> String {
        var tstring=string
        let first=tstring.firstCharacterRange()
        tstring.replaceRange(first, with:tstring.substringWithRange(first).lowercaseString)
        return tstring
    }

    public static func ucfirst(string: String) -> String {
        var tstring=string
        let first=tstring.firstCharacterRange()
        tstring.replaceRange(first, with:tstring.substringWithRange(first).uppercaseString)
