PHP Issue: How Do I insert raw HTML into .PHP scripts?

by edmltw
8 replies
The situation is like this:

I am using a shopping cart script that is coded in .php , and I want to add on a google analytic script to the index.php .

How do I actually add the raw html coding into the .php file?

Regards,
Ed
#html #insert #issue #php #raw #scripts
  • Profile picture of the author Mark Brian
    If it's inside the PHP code you should use something like:

    echo '<b>this is html';

    If it's outside, you can simply put it straight away.
    Signature

    {{ DiscussionBoard.errors[1390172].message }}
    • Profile picture of the author chaos69
      This is a simple request, but you will need to do this somewhere suitable in the script - I.E
      somewhere that is not in a loop, and if statement and such.


      If you want to do this at the end of the script, you can do this after the closing PHP tag, which is ?> - however, this may not be the best place for it.

      If you need to insert it before the end of the PHP script, you will need to

      close the tag; ?>
      Paste in your HTML
      and then reopen the tags <?php


      Alternatively, and this may be the safer option for you, if you do not want to break the php tags you can simply do the following in a suitable location.

      print <<<GACODE

      paste your GA code in here

      GACODE;


      If the index.php has a footer section, this would be an ideal location, just before the closing </html> tag.
      Signature
      Best Ways To Make Money Online

      Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
      “Yeah,” reply the bytes. “Make us a double.”
      {{ DiscussionBoard.errors[1390190].message }}
      • Profile picture of the author edmltw
        Originally Posted by chaos69 View Post

        Alternatively, and this may be the safer option for you, if you do not want to break the php tags you can simply do the following in a suitable location.

        print <<<GACODE

        paste your GA code in here

        GACODE;


        If the index.php has a footer section, this would be an ideal location, just before the closing </html> tag.
        Woah.. Pardon me for my ignorance, but what's a GACODE? MY bad..

        Ed
        Signature

        Need A Easy, Drag and Drop Website Creation Platform?
        Click Here To Find Out More

        {{ DiscussionBoard.errors[1390213].message }}
        • Profile picture of the author chaos69
          EDIT: Changed.
          You simply need to paste your Google Analytics code inside the print statement.

          print <<<GACODE

          paste your Google Analytics Code in here. or any HTML for that matter.

          GACODE;
          Signature
          Best Ways To Make Money Online

          Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
          “Yeah,” reply the bytes. “Make us a double.”
          {{ DiscussionBoard.errors[1390224].message }}
          • Profile picture of the author edmltw
            For example:

            ......require($template->get_template_dir('main_template_vars.php',DIR_WS_ TEMPLATE, $current_page_base,'common'). '/main_template_vars.php');
            /**
            * Read the "on_load" scripts for the individual page, and from the site-wide template settings
            * NOTE: on_load_*.js files must contain just the raw code to be inserted in the <body> tag in the on_load="" parameter.
            * Looking in "/includes/modules/pages" for files named "on_load_*.js"
            */
            $directory_array = $template->get_template_part(DIR_WS_MODULES . 'pages/' . $current_page_base, '/^on_load_/', '.js');
            foreach ($directory_array as $value) {
            $onload_file = DIR_WS_MODULES . 'pages/' . $current_page_base . '/' . $value;
            $read_contents='';
            $lines = @file($onload_file);
            foreach($lines as $line) {
            $read_contents .= $line;
            }
            $za_onload_array[] = $read_contents;
            }
            * print <<<GACODE
            <script EXAMPLE EXAMPLE EXAMPLE
            </script>


            ......

            Like that above? Thanks..

            Ed

            Originally Posted by chaos69 View Post

            EDIT: Changed.
            You simply need to paste your Google Analytics code inside the print statement.

            print <<<GACODE

            paste your Google Analytics Code in here. or any HTML for that matter.

            GACODE;
            Signature

            Need A Easy, Drag and Drop Website Creation Platform?
            Click Here To Find Out More

            {{ DiscussionBoard.errors[1390293].message }}
            • Profile picture of the author chaos69
              Originally Posted by edmltw View Post

              * print <<<GACODE
              <script EXAMPLE EXAMPLE EXAMPLE
              </script>


              ......

              Like that above? Thanks..
              You will need to include the closing tag as well;

              print <<<GACODE
              <script EXAMPLE EXAMPLE EXAMPLE
              </script>
              GACODE;


              ( However - i thought analytics usually went towards the end of the page, I.E before </body> or </html> - i'm not sure if it matters where you put it since i don't use it )
              Signature
              Best Ways To Make Money Online

              Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
              “Yeah,” reply the bytes. “Make us a double.”
              {{ DiscussionBoard.errors[1390306].message }}
    • Profile picture of the author edmltw
      Originally Posted by Mark Brian View Post

      If it's inside the PHP code you should use something like:

      echo '<b>this is html';
      So:

      echo '<b>this is html';
      <html>
      <etc. etc. etc.>
      </html> ?

      paste anywhere within the script?
      Signature

      Need A Easy, Drag and Drop Website Creation Platform?
      Click Here To Find Out More

      {{ DiscussionBoard.errors[1390202].message }}
  • Profile picture of the author gordi555
    Think people have their own way of doing this and might be confusing.

    Send the file to me, tell me exactly where you'd like it and I'll send it back with code inserted.

    Don't thank me, just give me money (joke)
    {{ DiscussionBoard.errors[1393583].message }}

Trending Topics