Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

Syntax highlighting

Options
  • 15-01-2014 8:29pm
    #1
    Closed Accounts Posts: 4,339 ✭✭✭


    I have a webpage that contains an iframe. I'm opening text files into that frame and I want to highlight java code in the text. I've googled syntax highlighters and came across geshi. Thing is I dont know much about php so I'm a bit confused as to how to use it even with the instructions for basic use.

    Here's the how to bit about the highlighter.
    //
    // Include the GeSHi library
    //
    include_once 'geshi.php';
     
    //
    // Define some source to highlight, a language to use
    // and the path to the language files
    //
     
    $source = '$foo = 45;
    for ( $i = 1; $i < $foo; $i++ )
    {
      echo "$foo\n";
      --$foo;
    }';
    $language = 'php';
     
    //
    // Create a GeSHi object
    //
     
    $geshi = new GeSHi($source, $language);
     
    //
    // And echo the result!
    //
    echo $geshi->parse_code();
    

    Can anyone explain how I use that in relation to the following bit of HTML ?
    <a href="page1.txt" target="iframe" onClick="showFrame()">Link to page 1</a>
    


Comments

  • Registered Users Posts: 4,757 ✭✭✭cython


    I have a webpage that contains an iframe. I'm opening text files into that frame and I want to highlight java code in the text. I've googled syntax highlighters and came across geshi. Thing is I dont know much about php so I'm a bit confused as to how to use it even with the instructions for basic use.

    Here's the how to bit about the highlighter.
    //
    // Include the GeSHi library
    //
    include_once 'geshi.php';
     
    //
    // Define some source to highlight, a language to use
    // and the path to the language files
    //
     
    $source = '$foo = 45;
    for ( $i = 1; $i < $foo; $i++ )
    {
      echo "$foo\n";
      --$foo;
    }';
    $language = 'php';
     
    //
    // Create a GeSHi object
    //
     
    $geshi = new GeSHi($source, $language);
     
    //
    // And echo the result!
    //
    echo $geshi->parse_code();
    

    Can anyone explain how I use that in relation to the following bit of HTML ?
    <a href="page1.txt" target="iframe" onClick="showFrame()">Link to page 1</a>
    


    Haven't used the library before, but at a guess you could hack your two sections together like this:
    [PHP]
    //
    // Include the GeSHi library
    //
    include_once 'geshi.php';

    //
    // Define some source to highlight, a language to use
    // and the path to the language files
    //

    // Assign your source instead of the sample given. Potentially you want to put a segment to read file contents into the $source variable as a string though, and then pass that to geshi
    $source = '<a href="page1.txt" target="iframe" onClick="showFrame()">Link to page 1</a>';

    $language = 'html'; //Assuming this is a valid option :-)

    //
    // Create a GeSHi object
    //

    $geshi = new GeSHi($source, $language);

    //
    // And echo the result!
    //
    echo $geshi->parse_code();[/PHP]


  • Closed Accounts Posts: 4,339 ✭✭✭Artful_Badger


    cython wrote: »
    Haven't used the library before, but at a guess you could hack your two sections together like this:
    [PHP]
    //
    // Include the GeSHi library
    //
    include_once 'geshi.php';

    //
    // Define some source to highlight, a language to use
    // and the path to the language files
    //

    // Assign your source instead of the sample given. Potentially you want to put a segment to read file contents into the $source variable as a string though, and then pass that to geshi
    $source = '<a href="page1.txt" target="iframe" onClick="showFrame()">Link to page 1</a>';

    $language = 'html'; //Assuming this is a valid option :-)

    //
    // Create a GeSHi object
    //

    $geshi = new GeSHi($source, $language);

    //
    // And echo the result!
    //
    echo $geshi->parse_code();[/PHP]

    I think you misunderstood me. I dont want to apply it to that line of html I want to apply it to the txt file that I'm sending into the frame with that line of html.

    So could I give it the file as a source and then direct the echo to the frame ? Or open a php file in the frame with that code using the file as a source ?


  • Registered Users Posts: 4,757 ✭✭✭cython


    I think you misunderstood me. I dont want to apply it to that line of html I want to apply it to the txt file that I'm sending into the frame with that line of html.

    So could I give it the file as a source and then direct the echo to the frame ? Or open a php file in the frame with that code using the file as a source ?

    Ah, I get you now, apologies for the mix up! I think half of your post just went straight out of my head as I read it :o

    Anyway, since you're going the route of an iframe, I would suggest potentially having a php script that can read a file whose name is passed, and simply echo that it out that as an appropriately highlighted string. You can then use this as the source/content of the iframe, and trigger changes in that as required, if you get me? Of course make sure that the file handling doesn't expose anything that it shouldn't too :)


Advertisement