These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | // This file passes the content of the Readme.md file in the same directory |
||
4 | // through the Markdown filter. You can adapt this sample code in any way |
||
5 | // you like. |
||
6 | |||
7 | // Install PSR-4-compatible class autoloader |
||
8 | spl_autoload_register(function($class){ |
||
9 | require str_replace('\\', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php'; |
||
10 | }); |
||
11 | // If using Composer, use this instead: |
||
12 | //require 'vendor/autoload.php'; |
||
13 | |||
14 | // Get Markdown class |
||
15 | use Michelf\Markdown; |
||
16 | |||
17 | // Read file and pass content through the Markdown parser |
||
18 | |||
19 | // Added $file variable for clarity |
||
20 | $file = 'readme.md'; |
||
21 | $text = file_get_contents($file); |
||
22 | $html = Markdown::defaultTransform($text); |
||
23 | |||
24 | // variable $title: Contains the first line of $file. |
||
25 | // Set the Webpage title dynamically so this can be used for any readme.md in any repo ... |
||
26 | // ... or other markdown documents at some point ... |
||
27 | |||
28 | $title = (new SplFileObject($file))->fgets(); |
||
29 | ?> |
||
30 | <!DOCTYPE html> |
||
31 | <html> |
||
32 | <head> |
||
33 | <title> |
||
34 | <? |
||
0 ignored issues
–
show
|
|||
35 | // Put title content in the document |
||
36 | echo $title |
||
37 | ?> |
||
38 | </title> |
||
39 | </head> |
||
40 | <body> |
||
41 | <?php |
||
42 | // Put HTML content in the document |
||
43 | echo $html; |
||
44 | ?> |
||
45 | </body> |
||
46 | </html> |
||
47 |
Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.
As a precaution to avoid these problems better use the long opening tag
<?php
.