Jump to content

Recommended Posts

Instead of using a regular expression, you could just create an array of values (A-J and k-t). You can then see if $checkChar is in the array with in_array(). More information about in_array() can be found here:

http://php.net/manual/en/function.in-array.php

 

Also note that you could create the array using a combination of range() and array_merge().

Link to comment
https://forums.phpfreaks.com/topic/290578-preg_match-help/#findComment-1488564
Share on other sites

What's the benefit? It's literally twice as much code and arguably less readable.

 

I guess it depends on what the code is used for. When I've had code like this in the past, the array of characters is used in other parts of the script. However, you're probably right about regular expressions fitting better in this case.

Link to comment
https://forums.phpfreaks.com/topic/290578-preg_match-help/#findComment-1488568
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.