Browse Source

php: fixed rpad,lpad,replace,htmlUnescape issues (thx Greg)

Franco Ponticelli 12 years ago
parent
commit
dce416dd87
1 changed files with 4 additions and 4 deletions
  1. 4 4
      std/php/_std/StringTools.hx

+ 4 - 4
std/php/_std/StringTools.hx

@@ -35,7 +35,7 @@
 	}
 	}
 
 
 	public inline static function htmlUnescape( s : String ) : String {
 	public inline static function htmlUnescape( s : String ) : String {
-		return untyped __call__("htmlspecialchars_decode", s);
+		return untyped __call__("htmlspecialchars_decode", s ,__php__("ENT_QUOTES"));
 	}
 	}
 
 
 	public static function startsWith( s : String, start : String ) : Bool {
 	public static function startsWith( s : String, start : String ) : Bool {
@@ -66,15 +66,15 @@
 	}
 	}
 
 
 	public inline static function rpad( s : String, c : String, l : Int ) : String {
 	public inline static function rpad( s : String, c : String, l : Int ) : String {
-		return c.length == 0 ? s : untyped __call__("str_pad", s, l, c, __php__("STR_PAD_RIGHT"));
+		return c.length == 0 || s.length >= l ? s : untyped __call__("str_pad", s, Math.ceil((l-s.length) / c.length) * c.length + s.length , c, __php__("STR_PAD_RIGHT"));
 	}
 	}
 
 
 	public inline static function lpad( s : String, c : String, l : Int ) : String {
 	public inline static function lpad( s : String, c : String, l : Int ) : String {
-		return c.length == 0 ? s : untyped __call__("str_pad", s, l, c, __php__("STR_PAD_LEFT"));
+		return c.length == 0 || s.length >= l ? s : untyped __call__("str_pad", s, Math.ceil((l-s.length) / c.length) * c.length + s.length , c, __php__("STR_PAD_LEFT"));
 	}
 	}
 
 
 	public inline static function replace( s : String, sub : String, by : String ) : String {
 	public inline static function replace( s : String, sub : String, by : String ) : String {
-		return untyped __call__("str_replace", sub, by, s);
+		return untyped sub=="" ? __call__("implode", __call__("str_split ", s) , by) : __call__("str_replace", sub, by, s);
 	}
 	}
 
 
 	public static function hex( n : Int, ?digits : Int ) : String {
 	public static function hex( n : Int, ?digits : Int ) : String {