Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

help with PHP comparison

help with PHP comparison

I'm using this code in my module:

Code:

 if ($society LIKE "%Richmond%") return 132;

I do not know much about PHP, but that's used in SQL which means I can search for the word Richmond in any - the % are wildcards.  Apparently, this is not supported in PHP, so what can I do for this?

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Re: help with PHP comparison

Hi thepiston,

there are a couple of ways to do this in PHP:

- the fastest way in terms of execution time:

if ( strpos( $society, "Richmond" ) !== false ) return 132;


- the one that's closest to SQL in terms of regular expressions:

if (preg_match("#.*Richmond.*#", $society ) ) return 132;

actually, you don't even need the .* characters (which are equivalent to % in SQL), so you could use:

if (preg_match("#Richmond#", $society ) ) return 132;

You do need the "#" characters at the start and end of the string though. Look up "regular expressions" if you want to understand what they are all about.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: help with PHP comparison

awesome thanks so much for this amazing app

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5933
Total Posts Today:
2
User Info:
 
Total Users:
4371
Newest User:
kajha63871
Members Online:
0
Guests Online:
212

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked