alfie: PHP-Maskierungen

Beitrag lesen

Hallo frankx!

Das versuchte ich mit der Trennung anzudeuten. Du musst ja doppelt escapen, einmal von PHP zu HTML, dort von JS zu HTML.

Das war der letzte Hinweis ;-)

Hier die funktionierende Version

  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">  
  <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
    <meta name="robots" content="noindex" />  
    <meta http-equiv="Content-Script-Type" content="text/javascript" />  
    <script type="text/javascript">  
      /* <![CDATA[ */  
        function Test1() {  
          alert("button no 1 clicked");  
          }  
        function Test2(text) {  
          if (text.length >= 1)  
            {  
              alert(text);  
            }  
          else  
            {  
              alert("call containing no text");  
            }  
          }  
      /* ]]> */  
    </script>  
    <title>JavaScript from PHP</title>  
    <style type="text/css">  
      html, body { margin:0; }  
      body {  
        font-size:100.01%;  
        padding:7px;  
      }  
      h1 { font-size:1.1em; }  
      p, form {  
        padding:10px;  
        border:1px solid #000;  
      }  
    </style>  
  </head>  
  <body>  
    <h1>Paragraph (PHP &gt; JavaScript &gt; HTML)</h1>  
    <?php  
      $JavaScript = '<script type="text/javascript">/* <![CDATA[ */document.write("<p>JavaScript active.</p>");/* ]]> */</script><noscript><p>JavaScript <strong>not</strong> active.</p></noscript>';  
      echo $JavaScript;  
    ?>  
    <h1>Form (plain HTML)</h1>  
    <form id="Form1a" action="">  
      <input type='button' name='test1a' id='test1a' value='button 1a' title='information 1' onclick="Test1();" /><br />  
      <input type='button' name='test2a' id='test2a' value='button 2a' title='information 2' onclick="Test2('Hello World!');" /><br />  
    </form>  
    <h1>Form (JavaScript &gt; HTML)</h1>  
    <form id="Form1b" action="">  
      <script type="text/javascript">  
        /* <![CDATA[ */  
          document.write("<input type='button' name='test1b' id='test1b' value='button 1b' title='information 1' onclick=\"Test1();\" /><br />");  
        /* ]]> */  
      </script>  
      <noscript>  
        <p>JavaScript <strong>not</strong> active (#1).</p>  
      </noscript>  
    <script type="text/javascript">  
      /* <![CDATA[ */  
        document.write("<input type='button' name='test2b' id='test2b' value='button 2b' title='information 2' onclick=\"Test2('Hello World!');\" /><br />");  
      /* ]]> */  
    </script>  
    <noscript>  
      <p>JavaScript <strong>not</strong> active (#2).</p>  
    </noscript>  
    </form>  
    <h1>Form (PHP &gt; JavaScript &gt; HTML)</h1>  
    <form id="Form2" action="">  
    <?php  
      $JavaScript = '<script type="text/javascript">/* <![CDATA[ */document.write("<input type=\'button\' name=\'test1\' id=\'test1\' value=\'button 1\' title=\'information 1\' onclick=\'Test1();\' /><br />");/* ]]> */</script><noscript><p>JavaScript <strong>not</strong> active (#1).</p></noscript>';  
      echo $JavaScript;  
    ?>  
    <?php  
      $JavaScript = '<script type="text/javascript">/* <![CDATA[ */document.write("<input type=\'button\' name=\'test2\' id=\'test2\' value=\'button 2\' title=\'information 2\' onclick=\"Test2(\'Hello World!\');\" /><br />");/* ]]> */</script><noscript><p>JavaScript <strong>not</strong> active (#2).</p></noscript>';  
      echo $JavaScript;  
    ?>  
    </form>  
  </body>  
</html>  

Dies Doppeltescaperei ersparst Du Dir m.M.N., indem Du JS dort definierst, wos hingehört, nämlich ins externe JS-Script.

Da hast ja recht, aber ich will es dabei belassen, neben einem 1000+ Zeilen PHP-Skript noch in einem 150+ Zeiler JavaScript - den ich noch viel weniger verstehe - herumzustochern.

Nocheinmal vielen Dank!

mfg Alfie