Within a function on my parent file, I am calling a function from an external php file. Here is my (simplified) code:
Parent file:
include "HelperFiles/htmlify.php";
function funcName(){
$description = "some sample text";
$description = htmlify($description, "code");
echo $description;
};
funcName();
htmlify.php file with called function:
$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;
}
};
I’m getting the following error:
Notice: Undefined index: text in C:_Localhost_Tools\HelperFiles\htmlify.php on line 25
I’ve tried declaring the $text variable inside and outside of scope in multiple places but can not seem to get around this error (warning). Any help would be greatly appreciated! Thanks.
replace
with
and you should not get the warning anymore.
However I would recommend to remove this alltogether. The function parameter should always be used – everything else is confusing.
And you can also remove the first line in htmlify.php – that does basically nothing.