RegExp in array_search or in_array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

RegExp in array_search or in_array

Post by anjanesh »

Anyway to get array_search to work with RegExp ?

Code: Select all

$pattern = "/something:.*?/i";
$key = array_search($pattern, $Fields);
Thanks
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Use a foreach loop and eragi, break the loop when a match is found (if you only want one match), otherwise build an array of matches.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ereg are horribly slow.. preg is always the way to do regex.
Post Reply