Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从textarea中剥离php标记?_Php - Fatal编程技术网

如何从textarea中剥离php标记?

如何从textarea中剥离php标记?,php,Php,我正在尝试从文本区域删除标记 我使用下面的代码在textarea中成功地打开了一个php页面,但我只希望代码在那里,并在textarea中从页面底部删除 这是我加载php页面的php代码: <?php $fn = "phpPage.php"; if (isset($_POST['content'])) { $content = stripslashes($_POST['content']); $fp = fopen($fn,"w") or die ("Error

我正在尝试从文本区域删除标记

我使用下面的代码在textarea中成功地打开了一个php页面,但我只希望代码在那里,并在textarea中从页面底部删除

这是我加载php页面的php代码:

<?php

$fn = "phpPage.php";

if (isset($_POST['content']))

{

    $content = stripslashes($_POST['content']);

    $fp = fopen($fn,"w") or die ("Error opening file in write mode!");


    fputs($fp,$content);

    fclose($fp) or die ("Error closing file!");

}

?>
这是我在文本区域加载页面的方式:

我尝试了这个,但没有给我任何错误:

strip_tags($fn, '<?php ?>');
有人能就此提出建议吗

谢谢


编辑:我已经尝试了所有的建议,但到目前为止没有一个有效。

请看这篇文章以获得灵感

$string = "SO.ME.TE.XT";
$string = str_replace(".","",$string);
echo($string);
将返回一些文本。因此

$string = YOUR PHP CODE;
$string = str_replace("<?php","",$string);
$string = str_replace("?>","",$string);
echo($string);
在你的情况下应该有用

更新1:

另一种方法是使用jquery和简单的替换脚本:

$(document).ready(function () {
    var codeContents = $("#code").val();
    $("#code").val(codeContents.replace("<?php","").replace("?>",""));
});

在php中不可能做到这一点。 有几种方法可以读取.php文件的内容:-

但是这些函数只能读取内容,而且这些函数不会返回输出,因此我们可以将它们分配给任何变量,并根据我们的意愿使用它们。 我们可以打印/显示.php文件的内容


好的,JKurcik共享的Jquery代码可以为您工作,但您面临的问题是,因为您在.php文件中使用了该代码***注意:在.php文件中,无论何时何地,我们都可以从底部删除wat?strip_标记,据我所知,这是您所需要的$content=stripslashes$_POST['content']$内容=带标签$content;您可以尝试将文本区域包装在标记中。Trip_标记在文件名上不起作用。或者它实际上会,但不是你想要的方式;但是我正在加载一个php文件,那么我需要怎么做呢?我已经更新了我的答案,并为你的问题添加了一个简单的javascript解决方案。很好,但是你的代码在线3中有一个语法错误!我已经对代码进行了测试,它可以正常工作。下面是它的JSFIDLE:
$(document).ready(function () {
    var codeContents = $("#code").val();
    $("#code").val(codeContents.replace("<?php","").replace("?>",""));
});
-> highlight_string(file_get_contents($fn));

-> readfile($fn);

-> $Vdata = file_get_contents($fn);
   $abc = var_dump($Vdata);
$(document).ready(function () {
    var codeContents = $("#code").val();
    $("#code").val(codeContents.replace("<?php","").replace("?>",""));
});