We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

[SOLVED] substr does not work with PHP in templates

Development and Programming

vw000's avatar
vw000
241 posts
4 years ago
vw000's avatar vw000

Is there a way to use the PHP substr function in a template?

This for example works:

$var =  '{username}'

echo $var

It will output the EE username.

But I tried different variations with substr and similar replace PHP functions and they will not work. Instead of trimming my username, it actually just trims the variable and EE ignores the value.

Example:

$var =  '{username}'
$foo = substr($var, 5);

echo $foo;

This actually parses {username}, the variable instead of the actual username. It will output:

name}

It properly cut the first 5 characters, but not from my username, but the variable itself.

EE ignores the variables inside that string completely. I tried print, double quotes, and even using other PHP function to replace or cut the username. No luck.

       
vw000's avatar
vw000
241 posts
4 years ago
vw000's avatar vw000

Asked for help for this on Slack and I was told to use logged_in_username instead of username and it works!

It seems EE parses that variable differently for some reason.

Thanks to Blair from Slack for the suggestion.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.