Quick function transformation...

Discussion in 'PHP' started by WebB3, Dec 17, 2010.

  1. #1
    Hey guys,
    I've been struggling with this for a while and was wondering if you guys could help me turn this function from javascript to php:

    // CONVERTS *ALL* CHARACTERS INTO ESCAPED VERSIONS.
    function escapeTxt(os){
    	var ns='';
    	var t;
    	var chr='';
    	var cc='';
    	var tn='';
    	for(i=0;i<256;i++){
    		tn=i.toString(16);
    		if(tn.length<2)tn="0"+tn;
    		cc+=tn;
    		chr+=unescape('%'+tn);
    	}
    	cc=cc.toUpperCase();
    	os.replace(String.fromCharCode(13)+'',"%13");
    	for(q=0;q<os.length;q++){
    		t=os.substr(q,1);
    		for(i=0;i<chr.length;i++){
    			if(t==chr.substr(i,1)){
    				t=t.replace(chr.substr(i,1),"%"+cc.substr(i*2,2));
    				i=chr.length;
    			}
    		}
    	ns+=t;
    	}
    	return ns;
    }
    
    Code (markup):
    All help will be deeply appreciated.
    Thank you.
     
    WebB3, Dec 17, 2010 IP