How can I use php script in xhtml file?
I have short_open_tags = Off in the php.ini and I tried to use <?php ?> or <script language="php"> </script> within xhtml file (I need to use xforms), but my php code is never parsed.
Why is that?

Thanks for advice.

Did you give the page a .php file extension?

If I give .php extension browser doesn't display the XForms. They are only displayed when the file is .xhtml. If I change to .php, can I send any header to tell the browser that it is an .xhtml file?

Do you run apache?

Yes. (Version 2)

We'll try to force apache to parse that file with the .xhtml extension as PHP. Put this code in an .htaccess file in the same directory as that .xhtml file:

<Files file.xhtml>
    ForceType application/x-httpd-php
</Files>

Change file.xhtml with whatever the real file name is. This should force the server to parse any PHP in there. Hopefully this won't break any compatibility with the xforms.

If this doesn't work, try adding a header to the page that indicates the content type is XHTML (not sure the right header info ATM).

Thanks for you advice, I tried to force the server to parse the php by adding the <Files directive, but it breaks the XForm - I got just back from browser just name of the labels.

I have tried various headers, but did not found the right one, none worked.

:?:

Thanks for you advice, I tried to force the server to parse the php by adding the <Files directive, but it breaks the XForm - I got just back from browser just name of the labels.

I have tried various headers, but did not found the right one, none worked.

:?:

Well, I'm not at all familiar with XFORMS, but you can use (assuming you're under Windows) Microsoft Fiddler to examine the data transferred. You can pick up the headers that are normally sent from your .xhtml file retrieval, and output the same from PHP.

MCP

You need to send this mime type with your PHP page and this should solve your problems: application/xhtml+xml

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.