Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8710597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:40:00+00:00 2026-06-13T04:40:00+00:00

I’m working with this code snippet plugin : http://www.steamdev.com/snippet/ for my blog but the

  • 0

I’m working with this code snippet plugin : http://www.steamdev.com/snippet/ for my blog
but the plugin doesn’t work on page load.
It only works at first page refresh.

I load my content in a specific div with jquery.ajax request and i’m trying this :

$(window).on("load", function(){ 
  $("pre.cplus").snippet("cpp",{style:"acid"});
  $("pre.php").snippet("php",{style:"acid"});
  });

I also tried to trigger the load event but i don’t know if it is correct..

Another question : i build my html with php string like this example:

$string = '<pre class="cplus">  
           #include <iostream>   
           int main()
           {
            //c++ code             
           }           
           </pre>

           <pre class="php">
           <?php
           function foo()
           {
            // PHP code
           }
           ?>
           </pre>';

echo $string;   // ajax -> success

but the PHP snippet shows empty (the c++ is ok). Any other way (or plugin) to show php code snippet on my page?
Thank you.

SOLVED:
The problem isn’t the plugin or Iserni suggestions.. i had a problem in page load (ajax)..
This is how i load the pages:

function pageload(hash) {
    if(hash == '' || hash == '#php')
    {
      getHomePage();
    }

    if(hash)
    {
     getPage();
    }

} 


function getHomePage() {
    var hdata = 'page=' + encodeURIComponent("#php");
    //alert(hdata);
    $.ajax({
        url: "homeloader.php",  
        type: "GET",        
        data: hdata,        
        cache: false,
        success: function (hhtml) { 
            $('.loading').hide();               
            $('#content').html(hhtml);
            $('#body').fadeIn('slow');      

        }       
    });
}

function getPage() {
    var data = 'page=' + encodeURIComponent(document.location.hash);
    //alert(data);
    $.ajax({
        url: "loader.php",  
        type: "GET",        
        data: data,     
        cache: false,
        success: function (html) {  
            $('.loading').hide();               
            $('#content').html(html);
            $('#body').fadeIn('slow');      

        }       
    });
} 

 $(document).ready(function() {

 // content
   $.history.init(pageload);    

    $('a[href=' + window.location.hash + ']').addClass('selected');

    $('a[rel=ajax]').click(function () {

        var hash = this.href;
        hash = hash.replace(/^.*#/, '');
        $.history.load(hash);   

        $('a[rel=ajax]').removeClass('selected');
        $(this).addClass('selected');
        $('#body').hide();
        $('.loading').show();

        getPage();

        return false;
    }); 
    // ..... other code for menus, tooltips,etc.

I know this is experimental , i have made a mix of various tutorials but now it works..
comments are much appreciated..
Thanks to all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:40:01+00:00Added an answer on June 13, 2026 at 4:40 am

    The PHP snippet seems empty because the browser believes it’s a sort of HTML tag.

    Instead of

    $string = '<pre class="php">
           <?php
           function foo()
           {
            // PHP code
           }
           ?>
           </pre>';
    

    you need to do:

    // CODE ONLY
    $string = '<?php
           function foo()
           {
            // PHP code
           }
           ?>';
    
    // HTMLIZE CODE
    $string = '<pre class="php">'.HTMLEntities($string).'</pre>';
    

    As for the jQuery, it is probably due to where you put the jQuery code: try putting it at the bottom of the page, like this:

    ....
    <!-- The page ended here -->
    <!-- You need jQuery included before, of course -->
    <script type="text/javascript">
        (function($){ // This wraps jQuery in a safe private scope
            $(document).ready(function(){ // This delays until DOM is ready
    
            // Here, the snippets must be already loaded. If they are not,
            // $("pre.cplus") will return an empty wrapper and nothing will happen.
            // So, here we should invoke whatever function it is that loads the snippets,
            // e.g. $("#reloadbutton").click();
    
            $("pre.cplus").snippet("cpp",{style:"acid"});
            $("pre.php").snippet("php",{style:"acid"});
    
            });
        })(jQuery); // This way, the code works anywhere. But it's faster at BODY end
    </script>
    </body>
    

    Update

    I think you could save and simplify some code by merging the two page loading functions (it’s called the DRY principle – Don’t Repeat Yourself):

    function getAnyPage(url, what) {
        $('.loading').show(); // I think it makes more sense here
        $.ajax({
            url: url,
            type: "GET",        
            data: 'page=' + encodeURIComponent(what),
            cache: false,
            success: function (html) { 
                $('.loading').hide();
                $('#content').html(hhtml);
                $('#body').fadeIn('slow');
            }
            // Here you ought to allow for the case of an error (hiding .loading, etc.)
        });
    }
    

    You can then change the calls to getPage, or reimplement them as wrappers:

    function getHomePage(){ return getAnyPage('homeloader.php', "#php"); }
    function getPage()    { return getAnyPage('loader.php', document.location.hash); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.