Link to home
Start Free TrialLog in
Avatar of NonComposMentis
NonComposMentisFlag for United States of America

asked on

PHP Failure Inside An MS Office Generated Webpage

Greetings Experts,

I have a problem with getting php to work inside a document that was auto-generated by MS Office (Outlook to be precise).  I had some code I wanted to put into the poppersinversion.org newsletter.  The newsletter is created in stages, one of which is normally to save an Outlook message to an html file.  This time, I decided to put some code in the page.  My Linux web host supports php, and I had previously had the code written and tested, but when put in the newsletter page it did not work.  In fact NO php code works inside the Office generated page.   You can see for yourself at http://www.poppersinversion.org/pos/2015/pos-2015-q3.php .  Look at the page source and search for the variable $report.  You can literally see the php code!  I suspect this has something to do with all the schemas that were loaded, but then which one and is it necessary?  Or is it something else?

Thanks,
NCM
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Nope.  I downloaded your page and ran it locally and it works fine.  For some reason, the PHP code is not being run in that page on your server.  That's what you have to look for.  See if there is an '.htaccess' file that is blocking it in that directory.
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NonComposMentis

ASKER

Thank you for your replies.

Ray - as far as the publishing strategy goes, you are probably right.

Dave, Ray - The problem is not squarely on the shoulders of my server.  As alluded to in my original question, the code I wanted to insert was already tested and working.

Here is a skeletal demo page with the very same php code that was in the newsletter link I gave you:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>PHP Working Demo</title>
    </head>
    <body>
        <h3>Text Before PHP code</h3>
        <?php
              $report = "<p>This sentence is inside php brackets.</p>";
              echo $report;
        ?>
      <h3>Text After PHP code</h3>
    </body>
</html>

I put it in the same folder as before:
http://www.poppersinversion.org/pos/2015/demo.php .

The demo works perfectly from my server.  So if the newsletter works for you and not me, there must be some interplay between my server and and the newsletter document that causes it to fail on my server.  If it helps, I'm linking the php configuration dump here.

The bottom line in this situation is that my hosting service is just going to say their php service works just fine.

Thank you,
NCM
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, hielo - That did it!

NCM
hielo resolved my issue and thereby earns the most points.  Ray Paseur put in significant effort and while he didn't get me to a resolution this time, he did provide me with a resource (validator.w3.org) which I will no doubt make good use of in the future.
That makes sense.  I downloaded your file and opened it in my code editor which probably removed the BOM because I certainly didn't see it.
For more information on the issues you may encounter when you're using the less popular (read "fringe") character encodings, check out this article.  PHP is making a full-on push to move to UTF-8.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11880-Unicode-PHP-and-Character-Collisions.html
Thanks, Ray.

Dave - I thought of that too, after the question was closed.  What if I just take what the browser sees as its "page source" and re-post that as a php file?  But right now I've got a deadline to meet.
No, that probably won't work because it doesn't automatically remove the BOM.  If your editor will do that, then it will work.