Jump to content

Drupal-Help needed-A newbie


aileia
 Share

Recommended Posts

I am using drupal 4.7x.

I write the following code in the blog entry

<?php

$life=42;

function meaningOfLife() {

global $life;

  print "The meaning of life is $life<br />";

}

meaningOfLife();

 

?>

 

and then select php code as input format.

The result turn out to be

 

The meaning of life is

 

which is wrong, apparently, what i want is

 

The meaning of life is 42.

 

This is an example given in php.net so it should be correct. Moreover since the function is executed, it confirms I installed php. However I can't define the variable $life in the function. It is printing the text, so it is calling the function however it is not calling the variable. Can anyone tell me what went wrong?

 

Link to comment
Share on other sites

Not enough to pin point whats causing it mate sorry :(

Can I suggest you add the code to a test.php file on your server and make sure that works ? as long as that works you can be 100% sure its drupal having some effect.

If not it could be something to do with your php.ini setup.

Link to comment
Share on other sites

globals are bad at the best of times, pass this variable into your function. eg;

 

<?php
$life=42;
function meaningOfLife($v) {
   print "The meaning of life is $v";
}
meaningOfLife();

?>

 

I would assume drupal uses eval or something to evaluate this code, and obviously globals won't work for whatever reason.

 

As for this....

My bad noticed another mistake -

 

replace this

$life=42;

 

 

with this

$life = '42';

 

Integers are not to be quoted.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.