Creating PHP File for Repeated Content

OK so this is exactly what put in the updates.php

<?php
$coupon_date = 'Offer expires last day of October 2013! Limit 1 per Client per year. Not valid with other offers.';
$analytics_code = '<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-20639892-2']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>';
?>

…then edited the above portion of the index.php with this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
include('updates.php');
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

…and also edited the portion of the page where I wanted these to be placed:

<?php echo $analytics_code ?>

and

<?php echo $coupon_date ?>

…then uploaded both updates.php and index.php, yet I still get this error message:

Parse error: syntax error, unexpected T_STRING in /home/content/08/6277108/html/airconditioningokc/updates.php on line 6

What mistake must I have done?

PHP is objecting to the string contents. In your google script, I’ve replaced all the inner single-quotes with double-quotes, as follows:


<?php
$promo_date = '15FEB13';
$analytics_code = '<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(["_setAccount", "UA-20639892-2"]);
  _gaq.push(["_trackPageview"]);

  (function() {
    var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;
    ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
    var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>';
?>

See how the strings in the

 tags are all red now - an unbroken string. It should run ok now.

Wow! This is great! It’s working real fine now! Thanks a bunch!!! :slight_smile:

So my next step now is to implement that command to all of the pages of the website. How do I do that? Should I rename all html extension pages with .php then?

Yes, add


<?php
include('updates.php');
?>

to all the pages that need the updates info and save them as .php files.

Then in your html, insert the php values:


<html><head><title></title>
<?php echo $analytics_code ?> <!--assuming the google javascript should be inside the <head> tags-->
</head>
<body>
<?php echo $coupon_date ?> <!-- this can be in the body like this or as a value in a form or in the cell of a table, anywhere really. -->
</body></html>

Should I also include these comments:

<!–assuming the google javascript should be inside the <head> tags–>

and

<!-- this can be in the body like this or as a value in a form or in the cell of a table, anywhere really. –>

or even without those comments it’s fine?

No, the comments were only to clarify the positioning for you. They can be removed

Ok. Thank you very, very much 2ndmouse!! You are such an angel! I wanted to thank you with you real name to make it more personal but your user is fine for now! I really appreciate your help. Thank you for your patience. :slight_smile:

I will update you every now and then if some problems still exist. I hope you don’t mind that. :slight_smile:

Glad it all worked out - happy coding