Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

embed php in javascript

Posted on 2008-06-18
13
Medium Priority
?
787 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
13 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 672 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 664 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 664 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.

704 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