1
   

Displaying <?php in javascript.

 
 
Reply Fri 22 Aug, 2003 07:11 pm
When I try to use this code on a php page it picks up <?php in the script thinking im going to use some php. How can I work around this? If you want the link to the page PM me for it. This script sends the following info to a textarea.

Code:
<script language="JavaScript">

/* Create the dataset and write to textarea */
function build_it_functions(form) {

/# Primary Variable */
functionsWizard=""
functionsWizard += "<?php\n\n"
functionsWizard += "// FILENAME: FUNCTIONS.INC.PHP\n"
functionsWizard += "function send_error_email( $error_code='Undefined' )\n\n"
functionsWizard += "{\n"
functionsWizard += " // set the TO: email address\n"
functionsWizard += " $to = '" + form.mailAddress.value + "';\n\n"
functionsWizard += " // set the SUBJECT: e-mail\n"
functionsWizard += " $subject = \"An error has occured - type: $error_code\";\n\n"
functionsWizard += " // set the MESSAGE: e-mail\n"
functionsWizard += " $message = \"The following error has occured:\\r\\n\"\n\n"
functionsWizard += " .\"--------------------------------\\r\\n\\r\\n\"\n"
functionsWizard += " .\" Type: $error_code\\r\\n\"\n"
functionsWizard += " .\" Page: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}\\r\\n\"\n"
functionsWizard += " .\" Time: \".date('d/m/Y H:i:s').\"\\r\\n\"\n"
functionsWizard += " .\" From IP: {$_SERVER['REMOTE_ADDR']}\\r\\n\\r\\n\"\n"
functionsWizard += " .\"Regards,\\r\\n\"\n"
functionsWizard += " .\"Your hard-working web server.\";\n\n"
functionsWizard += " $headers = \"From: webserver@{$_SERVER['SERVER_NAME']}\\n\"\n"
functionsWizard += " .\"Reply-To: webserver@{$_SERVER['SERVER_NAME']}\\n\"\n"
functionsWizard += " .\"X-Mailer: PHP/\".phpversion();\n\n"
functionsWizard += " // send the email\n"
functionsWizard += " mail( $to, $subject, $message, $headers );\n"
functionsWizard += "}\n\n"
functionsWizard += "?>"

/* Build It */
document.functionsWizard1.bundle_it_functions.value='<!-- Generator Coded by\: WWW\.************\.COM\, Script by *** -->\n<!-- Begin PHP Code -->\n\n' + functionsWizard + '\n<!-- End PHP Code -->'

}
</script>


Thanks Laughing
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 1 • Views: 6,583 • Replies: 20
No top replies

 
Monger
 
  1  
Reply Sat 23 Aug, 2003 01:08 am
What about just using the ascii values? Here's the ascii table for HTML.. http://www.w3schools.com/html/html_asciiref.asp

ie: <?php =
Code:<?php


Since I don't use PHP I'm not sure if that will prevent the PHP engine from seeing the tag, but I think there's a good chance.

And I suspect the string won't display properly in this post.
0 Replies
 
Monger
 
  1  
Reply Sat 23 Aug, 2003 01:13 am
Ah. As i thought, even in [ code ] tags this page is converting the ascii values, which means I can't post the code string. Just get the values from the above link.
0 Replies
 
Monger
 
  1  
Reply Sat 23 Aug, 2003 09:54 am
If that doesn't work, well since these (php-powered) pages display "<?php" just fine, Craven de Kere (web master here) should be able to give you the inside scoop. Smile
0 Replies
 
Craven de Kere
 
  1  
Reply Sat 23 Aug, 2003 03:09 pm
First of all let's see if we can take the easy way out. Does the page you are running that script on use php elsewhere? If not rename that page to an .html extention and you are all set.

If that is not acceptable I'll get back to you.
0 Replies
 
BobbyDouglas
 
  1  
Reply Sat 23 Aug, 2003 06:56 pm
Right now I am using GZip, so I need php on the page, also, once I finish the Login script on the left, it will require php as well...

I know it works on html pages, its just the fact I want to keep my site as much php oriented as I can.

So, any ideas on it?
0 Replies
 
Craven de Kere
 
  1  
Reply Sat 23 Aug, 2003 07:12 pm
Well, would you consider using straight php? There are workarounds for your method but you might as well get it right.

What is the script? Form to mail?
0 Replies
 
BobbyDouglas
 
  1  
Reply Sat 23 Aug, 2003 09:21 pm
It is form to textarea. Sent the link to your PM.

I would use straight php, but I am not experienced enough with it.
0 Replies
 
Craven de Kere
 
  1  
Reply Sat 23 Aug, 2003 10:11 pm
Then why not use the ascii?

Remove the spaces:

Code:& # 6 0 ; ?php
0 Replies
 
BobbyDouglas
 
  1  
Reply Sat 23 Aug, 2003 10:14 pm
It will display the ascii code then. Not the
Code:
<?php
0 Replies
 
Craven de Kere
 
  1  
Reply Sat 23 Aug, 2003 10:21 pm
Ok, I'm going out and I'll tackle this when I get home drunk. It's always easier to solve that way. Drunk
0 Replies
 
BobbyDouglas
 
  1  
Reply Sat 23 Aug, 2003 10:23 pm
Hahah, whatever works Smile
0 Replies
 
Craven de Kere
 
  1  
Reply Sat 23 Aug, 2003 10:40 pm
Ok, I did a bit of research because I figured there had to be another way. But I don't think there is.

You'll need to use ASCii for the "<"s and then replace them later with something like this:

Code:$text = str_replace(array(">", "<"), array(">", "<"), $text);
0 Replies
 
Craven de Kere
 
  1  
Reply Sat 23 Aug, 2003 10:42 pm
Anywho I really need to go get somethin' to drink but that should put you on the right track.

I can tell you right now it'd be a lot easier to just leave the script on an html page. Even if you IFRAME the html page in a php page. That would mean a lot less trouble.

As it stands you'll have to almost rewrite the script.

BTW, the above is a PHP example but it'd make more sense to use javascript I think.
0 Replies
 
BobbyDouglas
 
  1  
Reply Sun 24 Aug, 2003 12:19 am
OMG, i just thought of it!!!

How about this
Code:functionsWizard += "<"
functionsWizard += "?"
functionsWizard += "php\n\n"


I just dont make them with a \n OMG IM A GENIUS!!!!!!!!!
0 Replies
 
Monger
 
  1  
Reply Sun 24 Aug, 2003 04:39 am
Damnit you genious that was way too easy! Wink Arrrgh.
0 Replies
 
Craven de Kere
 
  1  
Reply Sun 24 Aug, 2003 04:41 am
Nice! <smacks forehead!>

That solution was begging to be used.
0 Replies
 
Jason
 
  1  
Reply Mon 25 Aug, 2003 11:48 am
OR, you could just use the escape character in Javascript which is "\", and write the line like:

functionsWizard += "\<\?php\n\n"

I tested it, and it works fine.
0 Replies
 
Craven de Kere
 
  1  
Reply Mon 25 Aug, 2003 12:04 pm
Jason I tried that are you sure it works with the script? Maybe I used teh wrong slash (I did it quickly) but I don't think so.
0 Replies
 
Craven de Kere
 
  1  
Reply Mon 25 Aug, 2003 12:05 pm
Welcome to Able2Know BTW!
0 Replies
 
 

Related Topics

\n - Question by negikaithal
PHP question about parse_url - Question by markalanbaker1
What does \n mean in PHP Code? - Discussion by roverroad
PHP Debate - Discussion by Craven de Kere
PHP: Cookie Problem - Discussion by BobbyDouglas
Installing PHP with IIS - CGI Error - Discussion by skinnz
php software - Question by aishna
 
  1. Forums
  2. » Displaying <?php in javascript.
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 04/26/2024 at 07:11:27