note 109468 added to function.urlencode

From: Date: Fri, 20 Jul 2012 00:38:03 +0000
Subject: note 109468 added to function.urlencode
Groups: php.notes 
Request: Send a blank email to php-notes+get-189301@lists.php.net to get a copy of this message
In response to LaKing at D250 dot hu, this is incredible bad practice. You should obviously never spam str_replace when you could instead do it like this: $array1[]="%C3%8D"; $array1[]="%C3%AD"; $array2[]="%CD"; $array2[]=%ED"; $string=str_replace($array1, $array2, $string); By the way, here is a function i wrote, (more on my blog): if (!function_exists("filesystemcode")){ function filesystemcode($string, $arr1="a", $arr2="b") { $c=array(); if (isset($arr1)) { if (!isset(${$arr1}) || !is_array(${$arr1})){ ${$arr1} = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D'); }} if (isset($arr2)) { if (!isset(${$arr2}) || !is_array(${$arr2})){ ${$arr2} = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]");}else{$b='';} } if (isset($a) && isset($b)){ return str_replace($a, $b, $string); }else{return($string);} } } Remove html compatible encoded illegal filename characters: //$string="%21dad"; $string=filesystemcode($string, "a", "c"); //echo $string; //"dad"; Remove illegal filename chars: //$string="/dad"; $string=filesystemcode($string, "b", "c"); //echo $string; //"dad"; Convert filesystem incompatible chars into html compatible chars: //$string="!dad"; $string=filesystemcode($string, "b", "a"); //echo $string; //"%21dad"; Convert html compatible chars into filesystem incompatible chars: //$string="%21dad"; $string=filesystemcode($string, "a", "b"); //echo $string; //"!dad"; ---- Server IP: 91.199.167.223 Probable Submitter: 195.240.207.53 ---- Manual Page -- http://www.php.net/manual/en/function.urlencode.php Edit -- https://master.php.net/note/edit/109468 Del: integrated -- https://master.php.net/note/delete/109468/integrated Del: useless -- https://master.php.net/note/delete/109468/useless Del: bad code -- https://master.php.net/note/delete/109468/bad+code Del: spam -- https://master.php.net/note/delete/109468/spam Del: non-english -- https://master.php.net/note/delete/109468/non-english Del: in docs -- https://master.php.net/note/delete/109468/in+docs Del: other reasons-- https://master.php.net/note/delete/109468 Reject -- https://master.php.net/note/reject/109468 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#189301) next »