在我的父文件的一个函数中,我从一个外部 php 文件调用一个函数。这是我的(简化的)代码:
父文件:
include "HelperFiles/htmlify.php";
function funcName(){
$description = "some sample text";
$description = htmlify($description, "code");
echo $description;
};
funcName();
带有被调用函数的 htmlify.php 文件:
$text = "";
function htmlify($text, $format){
if (is_array($_POST)) {
$html = ($_POST['text']);
} else {
$html = $text;
};
$html = str_replace("‘", "'", $html); //Stripping out stubborn MSWord curly quotes
$html = str_replace("’", "'", $html);
$html = str_replace("”", '"', $html);
$html = str_replace("“", '"', $html);
$html = str_replace("–", "-", $html);
$html = str_replace("…", "...", $html);
if ($format == "code"){
$html = str_replace(chr(149), "•",$html);
$html = str_replace(chr(150), "—",$html);
$html = str_replace(chr(151), "—",$html);
$html = str_replace(chr(153), "™",$html);
$html = str_replace(chr(169), "©",$html);
$html = str_replace(chr(174), "®",$html);
$trans = get_html_translation_table(HTML_ENTITIES);
$html = strtr($html, $trans);
$html = nl2br($html);
$html = str_replace("<br />", "<br>",$html);
$html = preg_replace ( "/(\s*<br>)/", "\n<br>", $html ); // seperate lines for each <br>
//$text = str_replace ( "&#", "&#", $text );
//return htmlspecialchars(stripslashes($text), ENT_QUOTES, "UTF-8");
return htmlspecialchars($html, ENT_QUOTES, "UTF-8");
}
else if ($format == "clean"){
return $html;
}
};
我收到以下错误:
注意:未定义索引:第 25 行 C:_Localhost_Tools\HelperFiles\htmlify.php 中的文本
我尝试在多个地方声明范围内外的 $text 变量,但似乎无法解决此错误(警告)。任何帮助将不胜感激!谢谢。