Avatar of NonComposMentis
NonComposMentis
Flag 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
Web DevelopmentPHPMicrosoft Office

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
Dave Baldwin

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
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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
hielo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
NonComposMentis

ASKER
Thanks, hielo - That did it!

NCM
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
NonComposMentis

ASKER
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.
Dave Baldwin

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.
Ray Paseur

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
NonComposMentis

ASKER
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.
Dave Baldwin

No, that probably won't work because it doesn't automatically remove the BOM.  If your editor will do that, then it will work.