472,353 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

How can I Display code as text like in these forums?

How can I display code as read only just like the code button option on this?

I want it to work for anything that is inputed not just php, or html, or mysql, or c# but one solution for all code input just a complete disabling and posting solution.

Expand|Select|Wrap|Line Numbers
  1. how do I do this?
Dec 21 '09 #1
18 3710
kovik
1,044 Expert 1GB
What part of it do you want?
  • The formatting is a fixed-width font. The most common web-safe monospaced font is 'Courier New.'
  • If you want the numbering, break each line into list items and make the entire element a list.
  • If you want the options above the code, you'll need to make them in JavaScript.
Dec 22 '09 #2
Thanks. What about having the code display as just readable text and not executing thats what im really after. Like the code bracket button. I'm using php, html, and java but it I can get it to display instead of execute

For example the below would show as text like it is instead of posting and trying to execute.


Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT * FROM accounts WHERE username = '$username'";
  2.   $result = mysql_query ($query);
  3. $number_of_results = mysql_num_rows($result);
  4.  
  5. if ($number_of_results != 1)
  6. {
  7. header("location: error.php?");
  8. exit();
  9. }
  10.  
  11.  
  12. // close connection
  13. mysql_close();
  14. ?>
  15.  
  16. <?php
  17. session_start();
  18. $username=$_SESSION[‘username’];
  19. $font=$_SESSION[‘font’];
  20. $linkc=$_SESSION[‘linkc’];
  21. $primaryc=$_SESSION[‘primaryc’];
  22. ?>
  23. <style type="text/css">
  24.  
  25. #demo-container{padding:25px 15px 0 15px;background:#dcdcdc;}
  26. #demog{margin:0;background:WHITE;}
  27.  
  28.  
  29. ul#simple-menu{list-style-type:none;width:100%;position:relative;height:27px;font-family:"Trebuchet MS",Arial,sans-serif;font-size:13px;font-weight:bold;margin:0;padding:11px 0 0 0;}
  30. ul#simple-menu li{display:block;float:left;margin:0 0 0 4px;height:27px;}
  31. ul#simple-menu li.left{margin:0;}
  32. ul#simple-menu li a{display:block;float:left;color:#fff;background:#696969;line-height:27px;text-decoration:none;padding:0 8px 0 8px;height:27px;}
  33. ul#simple-menu li a.right{padding-right:19px;}
  34. ul#simple-menu li a:hover{background:#696969;}
  35. ul#simple-menu li a.current{color:#696969;background:#fff;}
  36. ul#simple-menu li a.current:hover{color:#696969;background:#fff;}
thanks any insight is greatly appreciated
Dec 22 '09 #3
thanks. i added a better example I want to find out how to post the code as plain text like the code button allows you to do.
Dec 22 '09 #4
Dormilich
8,658 Expert Mod 8TB
this
Expand|Select|Wrap|Line Numbers
  1. $username=$_SESSION[‘username’];
should be
Expand|Select|Wrap|Line Numbers
  1. $username=$_SESSION['username'];
  2. // or
  3. $username=$_SESSION["username"];
(though it may come from an editor’s auto-conversion)
find out how to post the code as plain text like the code button allows you to do
you may want to explore the CSS of these code windows. as far as I can tell it’s just a special styled list, but it is all plain text. you may want to explore the <pre> and <code> HTML elements. (in XML you’d use a CDATA section to prevent code execution)
Dec 22 '09 #5
you wouldnt happen to know how to edit with auto-conversion for say multiple languages at once such as the code button here does?
Dec 22 '09 #6
Dormilich
8,658 Expert Mod 8TB
this’ forums editor has, afaik, no auto-conversion. it’s just a text field. and I’d discard any editor, which does auto-conversion I don’t want. the only thing [code] does is denoting a text, which is to be converted to the code list server side

PS. you can highlight PHP code with highlight_string() and highlight_file().

if you’re looking for a code editor, use something made for that purpose (Notepad++, Proton, SubEthaEdit, Bluefish, Geany to name only some)
Dec 22 '09 #7
kovik
1,044 Expert 1GB
The [code] tags here do NOTHING at all. They just display code in list format.

If you want something that highlights code, I'd highly suggest GeSHi, the "Generic Syntax Highlighter." I'd also suggest this addition to BYTES.com, but I'm sure they abandoned syntax highlighting for.. some reason. o.O
Dec 22 '09 #8
well if I insert that code now part of it displays but not all of it and then the code caused and error where I had to delete the post because it disabled the pages entire functionality.

Im thinking more of how to strip the code of anything that could cause problems with the database and php funcitonality and then placing it in a secure div for insertion and display, again your insight is much appreciated...
Dec 22 '09 #9
Dormilich
8,658 Expert Mod 8TB
database input has to be validated in any case.

what part is making the trouble?
Dec 22 '09 #10
hsriat
1,654 Expert 1GB
Do you need htmlentities/htmlspecialchars?
Dec 22 '09 #11
Markus
6,050 Expert 4TB
@kovik
No good reason that I could find. They said the old system we used was very buggy, yet I noticed nothing wrong with it. The issue has been brought up countless times but has always fallen on deaf ears.
Dec 22 '09 #12
thanks i think i should find my answer in htmlentities/htmlspecialchars really appreciate the help guys.
Dec 22 '09 #13
kovik
1,044 Expert 1GB
@Markus
Then it's abt time they started using GeSHi. ;)
The forums that I started out at use it, and they taught me everything that I know. Literally, everything. I didn't even know PHP, SQL, JavaScript, or CSS when I started going there. :P
Dec 22 '09 #14
Markus
6,050 Expert 4TB
@kovik
Well, there are many possible libraries to use. However there seems to be no interest from the owner (KUB) to test any of them. I have no idea how complicated it is to integrate plugins for vBulletin. I cannot understand why we're using vBulletin when there are free and better alternatives. Anyway, this conversation has headed off-topic.

Mark.
Dec 23 '09 #15
i used html specialchars and its working a little but not all the way im using mysql and php with java enabled. When i use html special chars and then decode to show the post its still causing errors when the code is used do you know of any good examples or ways around this?
Dec 28 '09 #16
Dormilich
8,658 Expert Mod 8TB
what kind of errors?

PS. you know that htmlspecialchars() is charset dependent?
Dec 28 '09 #17
hsriat
1,654 Expert 1GB
@leelotis
That happens when you are not doing encoding and decoding at right steps. Like you need to do some encoding before saving the text in database. This does not necessarily have to be specialchars, you can do it with mysql_real_escape_string, and then use specialchars when retrieving.
Also understand that specialchars and real escape are not complimentary to each other. Specialchars will help you to show the HTML content safely on the browser, while real_escape will make sure there's unsafe-to-database character present in the text.
You may need to do some extra encoding-decoding depending upon what type of text you are dealing with.
Dec 28 '09 #18
i did it and it works great. Thanks again.
Dec 28 '09 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: David Thomas | last post by:
Hi there, a while ago, I posted a question regarding reading japanese text from a text file. Well, since I solved the problem, I thought I'd post...
4
by: hoke | last post by:
I want to display plain text files in the browser. The files contain html and javascript and have a .txt extension. This works fine with files...
1
by: tfs | last post by:
I have a dropdownlist: <asp:dropdownlist id="recurrance" runat="server"> <asp:listitem value="0" >None</asp:listitem> <asp:listitem value="1"...
4
by: Tigrou | last post by:
Hello, In a Oracle Database i have text who are stored, this text are in RTF format, you can see an example below: ...
0
by: Doots | last post by:
Hello, Since 2 months i'm looking for a solution for display rtf text in an aspx page. The only component who can do it is RichTextBox but it's...
1
by: Tracey | last post by:
Hi, there My application requires to display multiline text in the cell of datagrid. I set the preferredheight of datagrid's tablsstyle, however,...
3
by: jiayanxiang | last post by:
Is there any sample code to use Javascript to load and display a text file? It will be best if the user can select files using some kind of...
1
by: =?Utf-8?B?bWFuanUxMjM0?= | last post by:
Hi, I need to write a code where if the user selects a radio button depending on that i need to display the text. can any one tell me how i can...
6
by: aliasDyego | last post by:
Hi all, I am trying to display both text and image fields from MySQL in PHP page but unfortunately it doesn't work. Here is the code i used: ...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.