NetTalk Central

Author Topic: Processing PHP in XHmtl tab not working  (Read 2550 times)

wasatchconsulting

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
    • Email
Processing PHP in XHmtl tab not working
« on: August 07, 2013, 04:37:56 PM »
I would like to run some PHP in the XHtml to post code based on a condition. I wanted to test this using the example in the PHP (58) folder (which I renamed to PHP) for this. The "pattern.php" runs just fine, but the same code in the XHtml tab in the MailboxesFormControl does not run in the example. It prints the code after the "print" command.

I would like to post the following PHP code in the PageHeaderTag procedure at the TOP:

<?php
     if(stripos($_SERVER['SERVER_NAME'],"test",0) > 0);?>
        <img src="images/test01.png"/>
<?php else;?>
        <img src="images/test02.png"/>
<?php endif;?>

Thanks
Ken

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Processing PHP in XHmtl tab not working
« Reply #1 on: August 07, 2013, 09:22:25 PM »
Hi Ken,

>> I would like to run some PHP in the XHtml to post code based on a condition.

The short answer is - this is the wrong approach.
PHP is a server side language. In other words it is parsed through a PHP engine before being sent to the client.
But in a NetTalk app you alreayd have a server side language (ie Clarion) so "embedding" PHP like this is overkill.
The correct approach is to port your PHP test into clarion.

So using the example below;
a) add an item to the xHtml tab - doesn't matter what you put in there, the goal is to see how the text in there is handled.

b) right click on the procedure, and choose "Source". search for the routine name specified in step a.
You should see a call to it, and the declaration of it.

c) In the routine, in the embed before the assignment, put your own code to print the packet variable. ie it might look something like;

If instring('test',something,1,1)
  packet = '<img src="images/test01.png"/>'
else
  packet = '<img src="images/test02.png"/>'
end


As an aside, you can not put PHP into the header anyway, because the PHP engine only reads html "whole pages" off the disk. it can't handle "snippets" of PHP generated into dynamic content. But fortunately this should never be required anyway.

Cheers
Bruce


I wanted to test this using the example in the PHP (58) folder (which I renamed to PHP) for this. The "pattern.php" runs just fine, but the same code in the XHtml tab in the MailboxesFormControl does not run in the example. It prints the code after the "print" command.