PHP Writing Javascript Code

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
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

PHP Writing Javascript Code

Post by tecktalkcm0391 »

Can you put something like:

Code: Select all

<script  scr="javascript.php?user=me"></script>
and have the PHP code just display the codes like this:

Code: Select all

<?php
// Javascript.php

print('
function createjsDOMenu() {
cursorMenu1 = new jsDOMenu(150);
  with (cursorMenu1) {
    addMenuItem(new menuItem("Dynamic Drive", "", "http://www.dynamicdrive.com"));
    addMenuItem(new menuItem("-"));
    addMenuItem(new menuItem("JavaScript Kit", "", "http://www.javascriptkit.com"));
    addMenuItem(new menuItem("Coding Forums", "", "http://www.codingforums.com"));
    addMenuItem(new menuItem("FreewareJava", "", "http://www.freewarejava.com"));
    addMenuItem(new menuItem("Search Engines", "se", ""));

}');

?>
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post by Robert Plank »

Yes that will work, why waste the time asking if you can try it out first.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Yes you can, however for chunks of code like that I prefer to drop out of PHP.
Robert Plank wrote:Yes that will work, why waste the time asking if you can try it out first.
Be nice.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

astions wrote:
Robert Plank wrote:Yes that will work, why waste the time asking if you can try it out first.
Be nice.
It wasn't an unreasonable request, nor a rude way to request it, in my opinion.

However, perhaps there was a reason he didn't try it first? (I'm playing devils advocate here)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Robert Plank wrote:Yes that will work, why waste the time asking if you can try it out first.
Some folks just want the comfort of having someone else try a potentially dangerous solution out before killing their own system :wink: .

Hey, I have been guilty of this on more than one ocassion. But Feyd usually knows what would have happened and expectedly gives me some insight into the future of what could have been my disastrous stupidity.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Roja wrote:It wasn't an unreasonable request, nor a rude way to request it, in my opinion.
When I worked at a bank, they said, "It's not what you do, it's the way others perceive what you are doing", referring to any actions that seem to be "shady". I think this concept would also apply in the forum. It's not what you say, so much as how others perceive what you are saying. My first reaction to that post was, "Wow that's a little bit harsh".
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Everah wrote:
Robert Plank wrote:Yes that will work, why waste the time asking if you can try it out first.
Some folks just want the comfort of having someone else try a potentially dangerous solution out before killing their own system :wink: .
So people can write bad code, let others run it, and let them risk it "killing their system" ?

Thats all kinds of a bad idea, ignoring that php code doesn't really kill a system usually. ;)

Better questions come when you test things yourself first. Lets encourage that behavior.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

<offtopic>
Can someone please test this for me.. :twisted:

Code: Select all

while (1 < 2) {
$filename = rand(0,9999999);
touch($filename);
}

// WARNING, DO NOT RUN THIS CODE!!!
</offtopic>

Edit: I ran this code and it created 94,263 files in 600 seconds.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Roja wrote:
Everah wrote:
Robert Plank wrote:Yes that will work, why waste the time asking if you can try it out first.
Some folks just want the comfort of having someone else try a potentially dangerous solution out before killing their own system :wink: .
So people can write bad code, let others run it, and let them risk it "killing their system" ?

Thats all kinds of a bad idea, ignoring that php code doesn't really kill a system usually. ;)

Better questions come when you test things yourself first. Lets encourage that behavior.
I totally agree with you. Its just that I can almost 'hear it in their voice' when they post those types of questions. They are either too lazy to try it or are too scared. Those of us that know better 8) know not evaluate code that will cause issues.

I guess what I am saying here is that I do not condone what these folks are doing. I am just trying to sort of explain what I think they do it. I will be the second (you being the first) to encourage proper testing of ones code before posting errors or questions about it.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

astions wrote:<offtopic>
Can someone please test this for me.. :twisted:

Code: Select all

while (1 < 2) {
$filename = rand(0,9999999);
touch($filename);
}

// WARNING, DO NOT RUN THIS CODE!!!
</offtopic>

Edit: I ran this code and it created 94,263 files in 600 seconds.
Insanely funny :lol: :lol: :lol: .
Post Reply