Monday, September 26, 2011

Executing PHP code in Drupal

/* Assigning a PHP code into a variable or
We can load PHP code based block content into a variable */

$phpContent = '
<?php
$sampleString = "my sample content!";
echo "Length of <i>" . $sampleString . "</i> is : " . strlen($sampleString);
?>';

/* PHP code is processed and giving output */
echo drupal_eval($phpContent);

Output:

Length of my sample content! is : 18

No comments:

Post a Comment

Followers