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.

Strip some text from a field?

September 07, 2011 5:44am

Subscribe [2]
  • #1 / Sep 07, 2011 5:44am

    JamesBrighton

    146 posts

    My EE site pulls in data from an external source and adds it as content to a channel. One of the fields is payment and look something like this:
    £ 38000.00 per annum

    Is there a way of just stripping the decimal point so the filed becomes?:
    £ 38000 per annum

    This should probably be done on import, but the system has been set up and cant really be changed now. New data is periodically imported so I cant just change the content thats already in the system.

    Is there a way of changing the display of the field? Could any occurrence of ‘.00’ be removed?
    Thanks

    [Mod Edit: Moved to the Community Help forum]

  • #2 / Sep 07, 2011 10:17am

    Lee Powell

    88 posts

    Hi James - you could try Christopher Reding’s ‘String Replace’ plugin, available here: http://devot-ee.com/add-ons/string-replace-exp

    And use it like so:

    {exp:strrexp pattern=".00" replace="" string="{your_content}" }

    Alternatively, if you didn’t want to use a plugin, you could enable PHP on the parse output stage and use the following:

    <?php
    echo str_replace(".00", "", "{your_content}");
    ?>

    Although my preference would be to keep PHP away from templates and hand it off to a plugin where possible.

  • #3 / Sep 07, 2011 10:18am

    JamesBrighton

    146 posts

    Thanks a lot.

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

ExpressionEngine News!

#eecms, #events, #releases