David Beroff (d4b) wrote,
David Beroff

  • Mood:

Turning PHP on and off in unexpected places

I was back poking around boutell's Accountify, when I learned something new:
PHP allows us to shift in and out of "PHP gear" any time we want... even right in the middle of an if statement.

So I decided to try this... and it works! :-) I took the code that "activates" the opportunity map on pages of SafeAmericanKids.com that need one, and replaced the mildly-messy code (including echoes, escaped quotes and newlines)...
if ($map)
   echo "<script src=\"http://maps.google.com/maps/api/js?sensor=false\"\n";
   echo "type=\"text/javascript\"></script>\n";
   echo "<script src=\"/includes/StyledMarker.js\" type=\"text/javascript\"></script>\n";

... with a slightly-less-messy version that seamlessly flows from PHP to HTML and then back to PHP:
if ($map)
   <script src="http://maps.google.com/maps/api/js?sensor=false"
   <script src="/includes/StyledMarker.js" type="text/javascript"></script>
Tags: mtat, sak, webdev

  • (no subject)

    [I was recently asked to introduce my skills to a small, private mastermind. Here's what I wrote.] I see my specialty as being a bridge between…

  • Recent videos...

    A collaborative effort with Adam Fulford for one of his local retail business clients: The Magic Members Quick Setup Guide, currently on their…

  • Even Nigerian Princes Demand the BEST Ghost Writers!

    We all know about the Nigerian Prince scam, but did you know THEY use ghost-writing services, too? Read the whole story here! #ad (A 3-way…

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.