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.

substr with EE?

July 14, 2010 8:30am

Subscribe [2]
  • #1 / Jul 14, 2010 8:30am

    GlynD

    14 posts

    I’m trying to do something similar to getting the first letter of a user’s screen name.

    Does anybody know if it is possible to do something like this?:

    <?php echo substr({screen_name},0,1); ?>

    I’m using EE16.8 and the PHP is being parsed on input.

    Thanks guys

  • #2 / Jul 14, 2010 2:37pm

    Gareth Davies

    491 posts

    This should work:

    <?php echo substr("{screen_name}",0,1); ?>
  • #3 / Jul 14, 2010 3:06pm

    GlynD

    14 posts

    Thanks gareth

    I found that I could do it in the SQL statement too.

    {exp:query sql='SELECT LEFT(m_field_id_1,1) AS first_letter FROM exp_member_data'} 
    {first_letter}
    {/exp:query}
  • #4 / Jul 15, 2010 4:11am

    GlynD

    14 posts

    I’ve ran into another problem. I want to have the single letter in upper case so tried this:

    <?php 
        $upperCaseChar = strtoupper("{first_letter}"); 
        echo $upperCaseChar;
    ?>

    But all it outputs is {FIRST_LETTER} in uppercase. Presumeably this is because the php is being parsed before the EE query?

  • #5 / Jul 15, 2010 4:14am

    GlynD

    14 posts

    Not to worry. I modified my SQL statement to this:

    {exp:query sql='SELECT UPPER(LEFT(m_field_id_1,1)) AS first_letter FROM exp_member_data'} 
    {first_letter}
    {/exp:query}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases