Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I having issues with variable scope in an external file function?
    text
    copied!<p>Within a function on my parent file, I am calling a function from an external php file. Here is my (simplified) code:</p> <p>Parent file:</p> <pre><code>include "HelperFiles/htmlify.php"; function funcName(){ $description = "some sample text"; $description = htmlify($description, "code"); echo $description; }; funcName(); </code></pre> <p>htmlify.php file with called function:</p> <pre><code>$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), "&amp;bull;",$html); $html = str_replace(chr(150), "&amp;mdash;",$html); $html = str_replace(chr(151), "&amp;mdash;",$html); $html = str_replace(chr(153), "&amp;trade;",$html); $html = str_replace(chr(169), "&amp;copy;",$html); $html = str_replace(chr(174), "&amp;reg;",$html); $trans = get_html_translation_table(HTML_ENTITIES); $html = strtr($html, $trans); $html = nl2br($html); $html = str_replace("&lt;br /&gt;", "&lt;br&gt;",$html); $html = preg_replace ( "/(\s*&lt;br&gt;)/", "\n&lt;br&gt;", $html ); // seperate lines for each &lt;br&gt; //$text = str_replace ( "&amp;amp;#", "&amp;#", $text ); //return htmlspecialchars(stripslashes($text), ENT_QUOTES, "UTF-8"); return htmlspecialchars($html, ENT_QUOTES, "UTF-8"); } else if ($format == "clean"){ return $html; } }; </code></pre> <p>I'm getting the following error:</p> <p>Notice: Undefined index: text in C:_Localhost_Tools\HelperFiles\htmlify.php on line 25</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload