file_get_contents从C程序中删除include头文件


file_get_contents remove include header files from a C program

有一个C程序文件托管在github上,我正试图从其原始文件url中使用php获取其内容。这是我目前正在使用的代码。

<?php
$x = file_get_contents("https://raw.githubusercontent.com/HiteshGarg/codingeek/master/Data-Structure/Queue/PriorityQueue.c");
echo $x;
?>

这是能够获取文件,但它删除了<stdio.h> and <stdlib.h>,并考虑他们作为HTML标签时,试图呈现他们追加他们的结束标签,如-

#include<stdio.h>
#include<stdlib.h>
//Other CODE in FILE 
</stdlib.h></stdio.h>

我也试过使用curl,但是没有运气。

$curl = curl_init('https://raw.githubusercontent.com/HiteshGarg/codingeek/master/Data-Structure/Queue/PriorityQueue.c');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$x = curl_exec($curl);
echo $x;

有什么方法可以显示这个吗?

编辑- 实际情况是,我正在使用Wordpress,我必须将此代码嵌入到代码高亮中。为此,我添加了一个短代码,但这是在网页上显示的代码中显示额外的HTML标签。所以我不必在实际场景中使用echo或print,而是必须获得纯文本并将其合并到现有的post中。

在你披露了这个场景之后,解决方案是转义html序列,这样你的wordpress就不会再自动关闭标签了。

<?php
$x = file_get_contents("https://raw.githubusercontent.com/HiteshGarg/codingeek/master/Data-Structure/Queue/PriorityQueue.c");
echo htmlentities($x);
?>

(编辑:删除之前的旧答案)