Jump to content

PHP Code Snippet library


scvinodkumar

Recommended Posts

Hi,

Do you take suggestions when they're given to you? Have you tried any of the suggestions people posted? If not, I don't see why we should give help to you.

 

If you don't want to take my advice and you are very curious about how SMF (the forum software used here on PHPFreaks) does it, then download SMF and view the source code. I never used SMF so I have no idea what file to tell you to look at.

 

The


are BB Codes. They're in almost every forum software. You can write a simple parser for that using preg_replace.

 

Thanks!

Hi,

 

Yeah, i tested those code given by gevans, but it is not displaying any thing there when i add the php code in the test.html file

 

the code that i added in the html file is

<pre class="brush: php;">
<?php
if (isset($parameter) && $parameter != "") 
    {
        if ($parameter == "PUBLIC") 
        {
            $run_result = true;
        } 
        else if ($parameter == "LOGGED_IN" && isset($_SESSION['userid']) && $_SESSION['userid'] != "" && $_SESSION['userid'] != -1) 
        {
            $run_result = true;
        }
    }
?>
</pre>

 

And the output comes as

 

SyntaxHihglighter Test This is a test file to insure that everything is working well.  1. (empty line)

 

 

Hi,

 

Again, I tried a function used at php.net with highlight_string, this time the colors displayed correctly, but the i got the following output,

 

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php 

function printCode($code, $lines_number = 0)    { 
               
         if (!is_array($code)) $codeE = explode("\n", $code); 
        $count_lines = count($codeE); 
        
        $r1 = "Code:<br />"; 

         if ($lines_number){            
                $r1 .= "<div class=\"linenum\">"; 
                foreach($codeE as $line =>$c) {     
                    if($count_lines=='1') 
                        $r1 .= "1<br>"; 
                    else 
                        $r1 .= ($line == ($count_lines - 1)) ? "" :  ($line+1)."<br />"; 
                 } 
                 $r1 .= "</div>"; 
         } 

         $r2 = "<div class=\"linetext\">"; 
         $r2 .= highlight_string($code,1); 
         $r2 .= "</div>"; 

        $r .= $r1.$r2; 

        echo "<div class=\"code\">".$r."</div>\n"; 
    } 

    printCode('<?php echo "PHP Code" ?>    ',1); 
?>

 

Hi,

 

Yeah, i tested those code given by gevans, but it is not displaying any thing there when i add the php code in the test.html file

 

the code that i added in the html file is

<pre class="brush: php;">
<?php
if (isset($parameter) && $parameter != "") 
    {
        if ($parameter == "PUBLIC") 
        {
            $run_result = true;
        } 
        else if ($parameter == "LOGGED_IN" && isset($_SESSION['userid']) && $_SESSION['userid'] != "" && $_SESSION['userid'] != -1) 
        {
            $run_result = true;
        }
    }
?>
</pre>

 

And the output comes as

 

SyntaxHihglighter Test This is a test file to insure that everything is working well.  1. (empty line)

 

So what you're saying is you didn't read the documentation, you don't know how to use it, you implemented it badly, you caused it not to give it, you deemed it useless?

Hi gevans,

 

Sorry, i was added the <?php and ?> in the HTML file, that's why it didn't show the result, now i removed it and working fine.

 

I know that i have worked stupidly, i am very sorry for this and wasted your precious time.

 

Thanks for helping you. I will try to avoid making such stupid mistake here after.

 

 

 

No worries, just try and make sure you take advantage of suggestions before overlooking them. In most cases when something goes wrong it will be your problem, not the app that you're using. I don't mean that in a bad way, I've pained over the smallest syntax errors myself!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.