Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   PHP Issue: How Do I insert raw HTML into .PHP scripts? (https://www.warriorforum.com/programming/145180-php-issue-how-do-i-insert-raw-html-into-php-scripts.html)

edmltw 16th November 2009 07:31 AM

PHP Issue: How Do I insert raw HTML into .PHP scripts?
 
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

Mark Brian 16th November 2009 07:48 AM

Re: PHP Issue: How Do I insert raw HTML into .PHP scripts?
 
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.

Luke Graham 16th November 2009 07:53 AM

Re: PHP Issue: How Do I insert raw HTML into .PHP scripts?
 
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.

edmltw 16th November 2009 08:00 AM

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

Originally Posted by Mark Brian (Post 1390172)
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?

edmltw 16th November 2009 08:03 AM

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

Originally Posted by chaos69 (Post 1390190)
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

Luke Graham 16th November 2009 08:07 AM

Re: PHP Issue: How Do I insert raw HTML into .PHP scripts?
 
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;

edmltw 16th November 2009 08:24 AM

Re: PHP Issue: How Do I insert raw HTML into .PHP scripts?
 
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

Quote:

Originally Posted by chaos69 (Post 1390224)
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;


Luke Graham 16th November 2009 08:32 AM

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

Originally Posted by edmltw (Post 1390293)
* 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 )

gordi555 17th November 2009 03:08 AM

Re: PHP Issue: How Do I insert raw HTML into .PHP scripts?
 
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) :)


All times are GMT -6. The time now is 02:43 AM.