Jump to content


PHP Highlight Tool From Form


9 replies to this topic

#1 Pbkilldezines

    Young Padawan

  • Members
  • Pip
  • 31 posts

Posted 15 November 2004 - 11:33 PM

Ok brfore I had it set up as this:
<?php highlight_file ("File Name"); ?>

But to make it easier so I dont have to keep uploading every time I made a form that would highlight it. Here is the code for the process:
<?php
$file = $_POST['file'];
highlight_file ('$file');
?>

When I try that I get errors. Its the the txt field name I checked that,

Anyone know why?

#2 Nascaron

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 16 November 2004 - 06:06 AM

Could you include your HTML form or explain what it does exactly?
What kind of file are you trying to highlight?
And are you trying to highlight a file that is on your PC or on your website?

#3 Pbkilldezines

    Young Padawan

  • Members
  • Pip
  • 31 posts

Posted 16 November 2004 - 07:02 AM

Well Im trying to higlight the PHP syantax o files.
Here is the code for the form page:
<html>
<head>
<title>Code Highlighter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#1d1d1d">
<table width="606" border="0" align="center">
<tr>
<td><div align="center"><font color="#CCCCCC">PHP Code Hihglighter</font></div></td>
</tr>
<tr>
<td height="93"><form name="form1" method="post" action="highlight.php">
<div align="center"><font color="#CCCCCC">File To Highlight:
<input type="text" name="file">
<input type="submit" name="Submit" value="Get Code">
</font></div>
</form></td>
</tr>
</table>
</body>
</html>

I dont remember the errors but I dont have time to try it agien right now.

#4 Nascaron

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 16 November 2004 - 07:27 AM

<?php
$file = $_POST['file'];
highlight_file ('$file');
?>

That is all of the content of the highlight.php file, right? Please answer the following questions:

What kind of file are you trying to highlight? (PHP, TXT, HTML, ASP, you name it)
Are you trying to highlight a file that is on your PC or on your website already? (if on your PC you'd first need it to get uploaded, or, directly copy and paste the source into a form and make that form view the text highlighted)

I think you are trying to highlight a file that's on your PC, but if so..why use a simple text input field to get the URL of the file?

Please explain.

#5 Pbkilldezines

    Young Padawan

  • Members
  • Pip
  • 31 posts

Posted 16 November 2004 - 03:24 PM

Wlell here it is, The files are PHP, they are on my server, and yes that is the code from the form processor.

???? Any ideas.

I want to use a text feild to enter the links in so I dont havr to keep iuloading the file everytime I want to highight something.

#6 Nascaron

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 16 November 2004 - 05:11 PM

The problem is, you'd need to upload them before they are on your server.

Try this:

<?php
if ($submit) { //check if submit is hit
  $file = $_POST['file'];
  highlight_file ($file); // I removed the quotation marks here
}
else {
  echo "Please use the form to submit a file first!";
}
?>


#7 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 21 November 2004 - 08:10 PM

well, if you don't want to upload them everytime you want something highlighted... the go the super easy way, highlight_string();

<input type="textfield" name="string"><br>
<input type="submit" name="submit" value="Submit>
<?
if($_POST['submit']){
highlight_string($_POST['string']);
}
?>

this should work, if you get confused or this didn't quite work you can check these 2 places for a little better explanation for more info on this:
My tutorial (includes how to choose the colors you want to be returned)
php.net

you should be able to do what you want with this, if you need any more help, just pm me and ill see what i can do

#8 Nascaron

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 22 November 2004 - 07:49 AM

rc69, I believe your code only highlights a certain string, while I think Pbkilldezines was talking about a file. The script I submitted in my previous post should actually highlight the code of the filename specified.

#9 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 22 November 2004 - 10:42 AM

well, what you believe is wrong

Quote

I want to use a text feild to enter the links in so I dont havr to keep uloading the file everytime I want to highight something.

highlight_string() can highlight just as much as highlight_file(), but it can work with varialbe strings as long as the code for this entire site, so you can use a text field to put it in, you just need to make sure to have the <? ?> tags around the entire thing, or it wont be highlighted
(for example, my tutorial used highlight_string() to highlight everything there that happens to be highlighted)

so really, my could would be a bit better for what he wants

#10 Nascaron

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 23 November 2004 - 03:03 AM

No offense, but you're either not understanding my post or his, since what he asks for is to highlight FILES not CODE.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users