473,325 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 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 3834
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 my solution for the benefit of other people with...
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 with just html. Unfortunately when showing files with...
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" >Daily</asp:listitem> <asp:listitem value="2"...
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: {\rtf1\ansi\ansicpg1252\deff0\deflang1036{\fonttbl{\f0\froman\fcharset0...
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 too expensive. Then if anyone know a solution for...
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, it is fixed. For text longer than that, the rest...
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 explorer. If that's complex, a text box to specify the...
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 do this ? Thanks in adavnce
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: $id = $_GET; $sql = "SELECT * FROM user,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.