How to preg_match an array?

Started on the old forum in September 2011 · view the original in the archive · old links redirect here

3 replies · 2,120 views · started 15 years ago · 1 min read

4 participants
s3nzo Developer · 156 posts #1

Let's say i have an array

$smileys = array(':)', ':(', ':D')

and i want to match part of that array how can i use preg_match to achieve this? Here's what i tried but it didn't work

if($preg = preg_match('/[[:alnum:]]/i', $smileys, $matches))
print_r($matches);

The error i get is

Warning: preg_match() expects parameter 2 to be string, array given
anabolik Newbie · 7 posts #2
$matches = array_map(function($string) { preg_match('/[[:alnum:]]/i', $string, $matches); return $matches; }, $smileys);
standalone Junior · 28 posts #3

anabolik is a popular programmer 🙂

subzero Super moderator Fellow · 3,954 posts #4

foreach("$smileys" as $smiles);

lol and list will go on

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close