I need help in converting JavaScript to PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tabariz
Forum Newbie
Posts: 4
Joined: Thu Apr 24, 2008 5:47 am

I need help in converting JavaScript to PHP

Post by tabariz »

I have a function in java script that I have no idea how to convert it into PHP and what are the equivalent codes for it

Code: Select all

//to Extract Updated time info string
function GetExchangeData(UrlResult)
{
Result=new String(UrlResult);
Str=Result.substr(Result.indexOf("Last Trade",0)+1);
 
//Get the Token after Last Trade string in between character ';' and "Bid" 
//Ex: Last Trade3:30PM · 46.49000Bid
 
BeginIndex=Str.indexOf(";",0)+2;
EndIndex=Str.indexOf("Bid",0)-1;
Data=Str.substr(BeginIndex,EndIndex-BeginIndex);
Str="";
return Number(Data);
}
 
can anyone help?
Jakei
Forum Newbie
Posts: 2
Joined: Thu Apr 24, 2008 7:57 pm

Re: I need help in converting JavaScript to PHP

Post by Jakei »

**variables start with a $ sign in php
<?php (this is the start php tag)

//your instructions here including declaration of variables
example:
function getName{
$result=new String(UrlResult);
if (isset($_POST[$name]))
{
return ($_POST[$name]);
}
else
return($default);

?> (this is the end tag of php)

2 good references to help you

1-http://www.w3schools.com/php/default.asp
2-www.php.net

hope that helps
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Re: I need help in converting JavaScript to PHP

Post by mattcooper »

tabariz wrote:I have a function in java script that I have no idea how to convert it into PHP and what are the equivalent codes for it
It should perhaps be pointed out to you that PHP executes on the server before the browser receives its output, whereas Javascript executes on the client side after the page has been served. Therefore, there is no "conversion" for Javascript into PHP.

Do you mean that you want to include this code in a page that will be evaluated by PHP?
Post Reply