Solved

embed php in javascript

Posted on 2008-06-18
13
778 Views
Last Modified: 2012-06-21
I have the following piece of code that I need to run on a server that does not support php so I have been advised to convert the entire code in javascript with document.write and have them as javascript functions. I am not sure how exactly it needs to be done as I am not very experienced in JS. Any kind of help will be sincerely appreciated. The code is as under




code.txt
0
Comment
Question by:sulentho
  • 4
  • 3
  • 3
  • +1
13 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 168 total points
ID: 21818168
sulentho,

You can't convert that to Javascript.  That script does server side operations like connect to a database, etc.  Client side script like Javascript can't do it.  Find out if your new server supports a different server language and convert the PHP to that server language (e.g. ASP, .NET, etc).  Javascript won't work at all.

Let me know if you have any questions or need more information.

b0lsc0tt

p.s.  That advise is shocking to say the least.  Javascript is never a great substitute for PHP or a server language.  In most cases, like this, it can't replace the server script.  If the advise came from someone that didn't even ask what the code does or look at it then I would be very cautious about other advise on PHP, Javascript, etc.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 21818179
sulentho,

By the way ... please don't take the PS note personal and it isn't meant to be a general statement on the person giving the advise.  Maybe there was some miscommunication.  Otherwise they just don't know PHP and Javascript.  Just a heads up. :)

b0lsc0tt
0
 
LVL 24

Assisted Solution

by:purplepomegranite
purplepomegranite earned 166 total points
ID: 21818282
As b0lsc0tt says, converting that code to Javascript is impossible.  But if you have a server, surely it supports some server-side scripting if not PHP - if it's IIS for example, you can write the code in ASP.  Without server-side scripting, your code won't work - it is as simple as that.
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21818288
Sorry, I didn't read your post completely it seems, b0lsc0tt... I have actually just repeated everything you said!!  Don't mind me, it's getting late...
0
 

Author Comment

by:sulentho
ID: 21819079
Thank you very much for the advice guys, I will find out further if the server has any kind of scripting language like ASP on it to help. Thanks so much for the help and have a great day
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 166 total points
ID: 21820169
Alternatively look into the costs of a php-enabled server. Depending on your situation it can be anything from shared-hosted $50 a year, to dedicated at hundred dollars a year.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 21823279
sulentho,
Your welcome!  Let us know if we can help more with this or you have a question about what you learn from your new host.  If you have a lot of PHP scripts and your new host will just not support them or your old DB then you might really consider what Roonaan suggested.  There are lots of hosting providers that offer PHP.

purplepomegranite,
No worries!  Thanks for noticing and the apology.  Get some rest so you will be very helpful when Sulentho needs more help.  Yesterday was like that for me too.  ;)

bol
0
 

Author Comment

by:sulentho
ID: 21827689
I need to echo the following lines of code in javscript which will in turn document.write the html . I am not sure about the string escape characters so will need your help on this. Any help on this will be appreciated. Thanks and have a great day


<a href="http://www.insidetoday.com/ban_click.php?id=<?=$hed_ban['banner_id']?>&url=<?=$hed_ban['link_url']?>" target="_blank"><? if($hed_ban['banner_image']){ ?><img src="http://www.insidetoday.com/bannerimages/<?=$hed_ban['banner_image']?>" alt="ad" width="468" height="60" border="0" /><? } ?></a>
 

this is what I have started with

header("Content-type: text/javascript");

echo "document.write('<a href="http://www.insidetoday.com/ban_click.php?id=<?=$hed_ban['banner_id']?>&url=<?=$hed_ban['link_url']?>" target="_blank"><? if($hed_ban['banner_image']){ ?><img src="http://www.insidetoday.com/bannerimages/<?=$hed_ban['banner_image']?>" alt="ad" width="468" height="60" border="0" />);";

Open in new window

0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21827714
Hate to say, but this is another question, which means you should start it as a new question and assign points accordingly.  As far as I can see, it isn't even related to the original question except for the fact it mentions JavaScript...
0
 

Author Comment

by:sulentho
ID: 21827743
Thank you purplepomegranite will do so accordingly.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 21828949
Feel free to post the URL of the new question in a comment here if you'd like our help on it too.  If you need anymore help or have a question about this question then let us know.

bol
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now