0

PHP is a server side language – but my current request is to have PHP at client (browser) side language. Let me explain – I will have a .html file which in some way have instruction to load a .php file. This .php file would interact with DB (or create a dynamic Java Script). Later this data would be dynamically displayed on the web html file using PHP functionality. Is the same possible? Can you please provide an example of same? What is the HTML include command to include a PHP files.

Is this possible – however if same is possible what is the HTML tags to do so?

Let me explain via some examples:

A.html

<html>
<head></head>
<body>
<ul>  
inlude <--"phpfile.php"-->
</ul>
</body>
</html>

Now "phpfile.php" will have

<?php for($i=1;$i<=5;$i++){ ?>
<li>Menu Item <?php echo $i; ?></li> 
<?php } ?>

So finally the HTML file would give to the user:

•Menu Item 1
•Menu Item 2
•Menu Item 3
•Menu Item 4
•Menu Item 5

Here is my real requirement. I have to implement HighChart Column Drill down chart in a web page. Now that is statically build using JS:

References:

Example 1 Example 2

I am trying to create a dynamic Nth level column drilldown Highchart. Since drilldown 'data' and its tags are suppose to be dynamic I need to generate a dynamic JS. Is the same possible via PHP

We have PHP installed in our web host and doing an AJAX call will not solve as I need HighChart JS script to be dynamic . AJAX call can give me data but can I have the JS script made as dynamic. Please see the example references in the question. It has a 'data' 'drilldown' JS array tags for your perusal.

For better clarity I am adding the HighChart data array that needs to be dynamic here:

   var colors = Highcharts.getOptions().colors,
      categories = ['MSIE', 'Firefox', 'Chrome', 'Safari', 'Opera'],
      name = 'Browser brands',
      level = 0,
      data = [{
            y: 55.11,
            color: colors[0],
            drilldown: {
               name: 'MSIE versions',
               categories: ['MSIE 8.0', 'MSIE 6.0', 'MSIE 7.0', 'MSIE 9.0'],
               level: 1,
               data: [{
                   y: 33.06,
                   drilldown: {
                       level: 2,
                       name: 'drilldown next level',
                       categories: ['a', 'b', 'c'],
                       data: [23,54,47],
                       color: colors[0]
                   }
               }, 10.85, 7.35, 2.41],
               color: colors[0]
            }
         }, {
             y: 21.63,
            color: colors[1],
            drilldown: {
               name: 'Firefox versions',
               categories: ['Firefox 3.6', 'Firefox 4.0', 'Firefox 3.5', 'Firefox 3.0', 'Firefox 2.0'],
               data: [13.52, 5.43, 1.58, 0.83, 0.20],
               color: colors[1]
            }
         }, {
            y: 11.94,
            color: colors[2],
            drilldown: {
               name: 'Chrome versions',
               categories: ['Chrome 10.0', 'Chrome 11.0', 'Chrome 8.0', 'Chrome 9.0', 'Chrome 12.0',
                  'Chrome 6.0', 'Chrome 5.0', 'Chrome 7.0'],
               data: [9.91, 0.50, 0.36, 0.32, 0.22, 0.19, 0.12, 0.12],
               color: colors[2]
            }
         }, {
            y: 7.15,
            color: colors[3],
            drilldown: {
               name: 'Safari versions',
               categories: ['Safari 5.0', 'Safari 4.0', 'Safari Win 5.0', 'Safari 4.1', 'Safari/Maxthon',
                  'Safari 3.1', 'Safari 41'],
               data: [4.55, 1.42, 0.23, 0.21, 0.20, 0.19, 0.14],
               color: colors[3]
            }
         }, {
            y: 2.14,
            color: colors[4],
            drilldown: {
               name: 'Opera versions',
               categories: ['Opera 11.x', 'Opera 10.x', 'Opera 9.x'],
               data: [1.65, 0.37, 0.12],
               color: colors[4]
            }
         }];

Also the final page would not be a .php page, I am looking for a way to make the 'data' array either of 1,2,3,4 ... Nth element JS array

4
  • 3
    This isnt possible. PHP is ONLY a server side language. You will have to send ajax requests back to the server if you need to use it. Commented Mar 14, 2012 at 13:47
  • you can submit form to a php file or by ajax(as Sam said). There is no way to execute php with the extension of html. Commented Mar 14, 2012 at 13:51
  • 1
    @Sohail — File extensions are not restrictions. Servers can be configured to pass .html files through mod_php. The PHP is still processed on the server though, not the client. Commented Mar 14, 2012 at 13:52
  • @Prakash: I think you are mixing your real requirements with ideas on how to implement them. First state your actual requirements. Commented Mar 14, 2012 at 13:58

3 Answers 3

4

No. Browsers do not have PHP interpreters.

The closest you can come is to have any client side logic written in a language that is supported by the browser (JS being the sane option) and make HTTP requests (this is Ajax) to a webservice (which could be written in PHP) that interacts with your database. Once that data is returned to the browser then the client side code can perform DOM manipulation.

Sign up to request clarification or add additional context in comments.

11 Comments

Try looking at AJAX and jQuery (for easy AJAX calls)
There are many fine libraries that are not jQuery. I'm fond of YUI and here is a collection of tiny, specialised ones.
That is true, I'm only suggesting jQuery because I find it easy for beginners to use (not saying other libraries aren't).
I just feel a need to fight jQuery's ubiquity :)
Doing an AJAX call will not solve as I need HighChart JS script to be dynamic . AJAX call can give me data but can I have the JS script made as dynamic. Please see the example references in the question. It has a 'data' 'drilldown' JS array tags for your perusal.
|
1

This is not possible to do in the exact way you described it . Further more - I find your question a bit odd , which suggest that maybe you do not exactly understand what is PHP or what you can achieve with it .

If your needs re only to have a LOCAL system (not public) you can always install a php server on LOCAL MACHINE to be accessed by you. If you need to see HTML surfix on the address bar for some reason - ou can make PHP serve HTML files with *.HTML surfix . to the user it will look like HTML.

That being said - you CAN include php in an HTML file - but without a server side they will not run ...

One method I have seen used (but never tried) is including it like javascript :

<script language="JavaScript" type="text/javascript"
src="http://www.mydomain.com/html.php"
<script>

and then

<?php
 $ref = $_SERVER['HTTP_REFERER'];
 $ser = "Server: ". $_SERVER['SERVER_NAME'] .  "Script name: ".  $_SERVER['SCRIPT_NAME'];
 echo "document.write('this is php code called from HTML file:'   );";
 echo "document.write('$ref');";
 echo "document.write('$ser');";
?>

But the usual is By editing your htaccess :

<Files yourpage.html>
AddType application/x-httpd-php .html
</Files>

or for single

AddType application/x-httpd-php .html

Or for .htm

AddType application/x-httpd-php .htm

Comments

0

You can't do this. PHP runs on the server, just as you stated at the beginning of the question.

However, you could use AJAX to dynamically call PHP scripts from your web page and display the results. This requires JavaScript to make the requests from the browser back to the server. It's not HTML with "instruction to load a .php file" - that's impossible. But JavaScript can be used as an intermediary to get results from a server side script. I suggest you do some research on AJAX and see if that can meet your needs.

1 Comment

Doing an AJAX call will not solve as I need HighChart JS script to be dynamic . AJAX call can give me data but can I have the JS script made as dynamic. Please see the example references in the question. It has a 'data' 'drilldown' JS array tags for your perusal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.