ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

modify exp:channel:entries with PHP

February 25, 2011 2:42pm

Subscribe [2]
  • #1 / Feb 25, 2011 2:42pm

    skgreene

    40 posts

    Hi -

    I’m trying to modify a string variable that comes from the exp:channel:entries tag with a reg-ex in php. I cant figure out how to get the variable into php. I’m allowing PHP in my template, and parsing it at output, but just cant get the EE variable in php. What am I missing?

    summer

  • #2 / Feb 26, 2011 1:57pm

    Greg Salt

    3988 posts

    Hi skgreene,

    What have you tried? A simple example like this should work:

    {exp:channel:entries channel="my_channel" limit="10"}
    <?php
    $title = '{title}';
    echo sprintf('Title is %s characters long', strlen($title));
    ?>
    {/exp:channel:entries}

    I recommend though that you think about making this a plugin rather than using PHP directly in the template. You will find it considerably easier to maintain, especially if you wish to use this again elsewhere, and as Greg Aker has demonstrated you will probably also find it faster.

    Cheers

    Greg

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases