/    Sign up×
Community /Pin to ProfileBookmark

Run a Function for Each Occurrence of a Substring Within a String

I’m looking for the most efficient way of searching through a string, and for each occurrence of a substring, run a function on it. Similar to the array_filter() function for arrays, except it would be on a string. I suppose I could break up the string into an array of words, but I don’t think that would be the most efficient method. Hoping somebody out there knows of a function I could use for that.

For example:

str_filter($search, $subject, $function_name);
and it would run
myFunction(&$value) { return TRUE; }

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 18.2010 — [url=http://php.net/preg_replace_callback]preg_replace_callback[/url]()
Copy linkTweet thisAlerts:
@tirnaMar 18.2010 — ..
×

Success!

Help @Jerail 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.6,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...