Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Coloring code.

  1. #1
    Regular Coder
    Join Date
    Nov 2006
    Posts
    247
    Thanks
    13
    Thanked 26 Times in 24 Posts

    Coloring code.

    Basically what I want to accomplish is this:

    PHP Code:
    include('file.php');

    if (isset(
    $_POST['input']) {
        
    $string str_replace('word1''word2'$string);
        echo 
    $string "word3";
    } else {
        exit(
    "this is text");

    Yes, that is just random PHP. What I basically want to accomplish is what the [php][/php] tag on CF (and all other vBulletin forums) does, color the different parts of the code to make it easier to understand. I want to do it for HTML though (not PHP). I assume it's done with many <span style="color:#xxxxxx"></span> tags around the string to color the text. The only way I can even imagine doing this is with several complicated and confusing str_replace() and array() tags. I know there's probably an easier technique, or at least I hope there is. Any help would be appreciated. Thanks.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    vB(and pretty much everyone) uses highlight_string()/highlight_file(). In the manual you can also find the color settings that you can change with ini_set()

  • #3
    Regular Coder
    Join Date
    Nov 2006
    Posts
    247
    Thanks
    13
    Thanked 26 Times in 24 Posts
    Good to know. I'm pretty sure those only work for PHP code though? I want to do it for HTML and CSS. If worse comes to worse, I'll just do it manually with styled tags <var>, <em>, <strong>, etc.. Like:

    Code:
    <var>#tagid a:hover</var> <em>{</em> color:<strong>#000000</strong>; <em>}</em>
    output:
    Code:
    #tagid a:hover { color:#000000; }

    It's take way more time to accomplish, but if it the only way, I'll manage. Just want to clarify whether or not there's a simpler PHP alternative first.
    Last edited by Majoracle; 01-01-2008 at 10:35 AM.

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •