STRPOS PHP function can be used in a template?

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
bzozoo
Registered User
Posts: 24
Joined: Mon Feb 11, 2019 6:33 am

STRPOS PHP function can be used in a template?

Post by bzozoo » Mon Feb 25, 2019 4:17 pm

Hi all!

I want to add {SCRIPT_NAME} value to a $x variable. This template tag returns different script values on different subpages. For example, on the main page, it returns with "INDEX" value.

I use PHP in template:

Code: Select all

      <!-- PHP --> 
$x = '<!-- ENDPHP -->{SCRIPT_NAME}<!-- PHP -->'; 
echo $x; 
   <!-- ENDPHP -->
But value is not good:

Code: Select all

// line 33 echo (isset($context["SCRIPT_NAME"]) ? $context["SCRIPT_NAME"] : null);
If I add to template {SCRIPT_NAME} to template html, the correct value visible on my page. There are not problem with this there.

But I want use SRIPT_NAME value with STRPOS function.

Code: Select all

if (strpos($x, 'member') !== false) { 
    echo ' - GOOD'; 
} else { 
   echo ' - NOT GOOD; 
}
I use special user pages (Examples: sitename.com/member/joe1 .... sitename.com/member/joe1 ... sitename.com/member/joeN)
I want that how JoeX watches his page, they see the GOOD text, but If JoeX watches the other page, see the NOT GOOD text.

This mehanism work, but not good for me:

Code: Select all

<!-- IF SCRIPT_NAME eq 'member' --> 
GOOD
<!-- ELSE -->
NOT GOOD
     <!-- ENDIF -->
Becouse If Joe21111 watches his page, he see nothing, becous his script value is "member/Joe21111"

But If I could to add member/Joe21111 value to a $x variable, I could use STRPOS function.

$x = 'member/Joe21111';

Code: Select all

if (strpos($x, 'member') !== false) { 
    echo ' - GOOD'; 
} else { 
   echo ' - NOT GOOD; 
}
Becous member is in member/Joe21111 value.

Other ideas are of interest to me on how to solve this.
The goal is to display GOOD on any user profile page (Example sitename.com/member/user1 ... sitename.com/member/user2 ... sitename.com/member/userN etc etc )

(Sorry my poor English, I am not English, but I hope Everybody understand what I want to ask)
Thanks your helps!

bzozoo
Registered User
Posts: 24
Joined: Mon Feb 11, 2019 6:33 am

Re: STRPOS PHP function can be used in a template?

Post by bzozoo » Tue Feb 26, 2019 9:44 pm

I got a very good answer to my problem in :arrow: this topic. ;)

Post Reply

Return to “phpBB Custom Coding”