/    Sign up×
Community /Pin to ProfileBookmark

PHP remove selected class

Hi,

I have this PHP code:

[CODE]<li class=”account-item has-icon
<?php if(is_account_page()) echo ‘ active’; ?>
<?php if ( is_user_logged_in() ) { ?> has-dropdown<?php } ?>”
>[/CODE]

and it returns this:

[CODE]<li class=”account-item has-icon has-dropdown”>[/CODE]

I want to remove “has-dropdown” class with may be preg_replace() function. How can I do that?

Thank you.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 02.2016 — My first thought is that it might make more sense to modify the code where you are adding that class to not add it? Either just get rid of that line, or if there is some additional criteria, add that criteria to that if() clause.

But if getting rid of it after the fact is your only choice, could you just use [B][FONT=Courier New]str_replace(' has-dropdown', '', $theString)[/FONT][/B] ?

PS: Actually, looking at the original code, it looks like you are immediately outputting it at that point, so probably the best solution is my initial suggestion: don't output it in the first place if you don't want it.
Copy linkTweet thisAlerts:
@kalonyaauthorDec 03.2016 — That's not exactly what I asked. It's a theme so I don't want to loose my changings on every update. There is also lots of "has-dropdown" in more classes, so I don't want them be effected. I'm trying to ask how can I remove it without changing, it doesn't have an id. The only unique thing is "account-item has-icon has-dropdown".
Copy linkTweet thisAlerts:
@NogDogDec 03.2016 — ...The only unique thing is "account-item has-icon has-dropdown".[/QUOTE]

Then...
[code=php]
$text = str_replace('account-item has-icon has-dropdown', 'account-item has-icon', $text);
[/code]
×

Success!

Help @kalonya spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...