PHPFunction to create document.write

I am looking for a PHP function that I can call like this:

function DocumentDotWrite($variable,$MaintainLines)

Where I can pass in a variable, if MaintainLines is set to true, it will create a document.write('') for each line, if it is set to false, it will remove all line breaks and create 1 statement. I guess it probably probably has to escape some html or quotes as well?
interclubsAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Roger BaklundConnect With a Mentor Commented:
Try this:
function DocumentDotWrite($variable,$MaintainLines) {
  if($MaintainLines) {
    $lines = explode("\n",str_replace("\r\n","\n",$variable));
    foreach($lines as $line) {
      $line = addslashes($line);
      echo "document.write('$line');\n";
    }
  } else {
    $variable = addslashes(str_replace(array("\r\n","\n"),'',$variable));
    echo "document.write('$variable');";
  }
}

Open in new window

0
All Courses

From novice to tech pro — start learning today.