[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.8

Need some help in porting a code from javascript to PHP

Asked by Collis_Dam in PHP Scripting Language, JavaScript, Algorithms

Tags: javascript to php, encrypting, porting

Hello!

Please help me!
I am currently working on a small project. I have port a javascript code to PHP. Don't ask, I just have to. :)
The problem is that I can't get my PHP code work. There are some errors.
The code is an encrypting code.

********************************************************************************
The shortened html:
<form name="fa">
<textarea id="f2"></textarea>
select name="et" onchange="encN=this.selectedIndex+1">
<option selected>1
<option>2
<option>3
<option>4
<option>5
</select>
<input type="button" value="Encode" onclick="writeOut()">

********************************************************************************
The original JavaScript:
<script language="javascript">
var encN=1;
function encodeTxt(s){
s=escape(s);
var ta=new Array();
for(i=0;i<s.length;i++)ta[i]=s.charCodeAt(i)+encN;
return ""+escape(eval("String.fromCharCode("+ta+")"))+encN;
}
function writeOut(){
document.forms["fa"].output.value="<"+"script language=javascript"+">document.write(unescape('%3C%73...bla..bla..bla..%74%3E'));dF('"+encodeTxt(document.forms['fa'].f2.value)+"')<"+"/script>";
}
</script>

NOTE: I have to get this **encodeTxt(document.forms['fa'].f2.value)** part with PHP!


My PHP code is not working! I think I've done my best, I am really just a beginner. Please help!

The error msg is:
Notice: Undefined offset: 67 in \\.host\Shared Folders\htdocs\encoder\encoder.php on line 29

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in \\.host\Shared Folders\htdocs\encoder\encoder.php(32) : eval()'d code on line 1
2          ( I don't know what is this number 2.. Maybe the final string?)

Please help me to fix my code!
Maybe just a few fix, but I can't do more!

Thank you! You are my only hope!

If it's help, the original result of the Javascript (that I want) for "ssp_1-10_img (000).jpg" (without quotes) in the **encodeTxt(document.forms['fa'].f2.value)** part (that I need) is:
ttq%602.21%60jnh%2631%2639111%263%3A/kqh1

********************************************************************************
My PHP code (extracted to a snippet for readability and line numbering by mplungjan, ee zape):
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
<?php //first line -- lines here are not edited, because of the line counting.
 
$encN = 1;
 
$txt = "ssp_1-10_img (000).jpg";
$codeKey = 1; // options are: 0 | 1 | 2 | 3 | 4
$encN = $codeKey+1;
 
function escape($str) {
	$str = bin2hex($str);
	$r="";
	for( $a=0; $a<strlen($str); $a+=2 )
	{	
		$r.="%".$str{$a}.$str{$a+1};
	}
	$r = strtoupper($r);
	return $r;
}
 
function encodeTxt($s){
	global $encN;
	$r="";
	$s = escape($s);
	$ta = array();
	for ($i=1; $i<=strlen($s); $i++) {
		$ta{$i} = ord(substr($s, $i, 1))+$encN;
	}
	for ($j=1; $j<=$i; $j++) {
		$r.= chr($ta{$j});
	}
	
	$r = escape(eval($r)).$encN;
	return $r;
}
 
echo encodeTxt($txt);
 ?>
[+][-]06/05/09 04:42 AM, ID: 24555359Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: PHP Scripting Language, JavaScript, Algorithms
Tags: javascript to php, encrypting, porting
Sign Up Now!
Solution Provided By: mms_master
Participating Experts: 2
Solution Grade: A
 
[+][-]06/05/09 04:45 AM, ID: 24555372Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/05/09 04:46 AM, ID: 24555381Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/05/09 07:18 AM, ID: 24556657Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/05/09 07:30 AM, ID: 24556800Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/06/09 08:45 AM, ID: 24563354Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/11/09 11:37 AM, ID: 24605364Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625