David Beroff (d4b) wrote,
David Beroff
d4b

  • 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.
(Source)

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)...
<?php
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:
<?php
if ($map)
   {
?>
   <script src="http://maps.google.com/maps/api/js?sensor=false"
   type="text/javascript"></script>
   <script src="/includes/StyledMarker.js" type="text/javascript"></script>
<?php
   }
?>
Tags: mtat, sak, webdev
Subscribe

  • Business begets business

    I got three more voice acting jobs since I last posted, with another one in the wings. I've become pretty convinced that the algorithm that Upwork…

  • Generating PDF's on-the-fly

    My investment firm client asked me for the ability to have their Members print current stock certificates from the database and the website,…

  • "This button does nothing"

    Yeah, I should be blogging more, but there's some sort of Law where, when you're trying to break away to go on vacation, that's the precise time that…

  • Post a new comment

    Error

    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.
  • 2 comments