/    Sign up×
Community /Pin to ProfileBookmark

search and replace

how do I search for the following symbols in the [B]first[/B] position of a variable and if not found insert a “=” ?

[QUOTE]

=, !=, <>, < and >

[/QUOTE]

$category=”<32″ would be ok (as would >32, <>32, =32 or !=32 )

but if $category=”32″ then change $category to be”=32″

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@pyroSep 08.2003 — Try something like this:

[code=php]<?PHP
$category = "32" ;
if (!preg_match("/^=|!=|<>|<|>/",$category)) {
$category = "=".$category;
}
echo $category;
?>[/code]
What the regexp does is check if the variable starts with any of the characters, and if it does not (due to the ! at the beginning of our if statement) it will concatenate a = to the beginning of the string.
Copy linkTweet thisAlerts:
@esmauthorSep 08.2003 — you are good! that is why you are a SUPER moderator!!

thanks!?
Copy linkTweet thisAlerts:
@pyroSep 08.2003 — lol... thanks ? I was happy to help...
×

Success!

Help @esm 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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...