'filtering' and php

Does anyone have a generic routine to strip both url's and emailadresses from a string?

as for stripping emailadresses, just stripping everything that is directly connected to a @ would work for my purposes.
LVL 12
j2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

maxkirCommented:

$string = "data to search in";

preg_match_all("/([\w\.-]+@[\w\.-]+)/i", $string, $emails, PREG_SET_ORDER);
preg_match_all("|(h?[f|t]tp://[\w-\.=\?&/%]+)|i", $string, $urls, PREG_SET_ORDER);

print "Emails:\n";
for($i=0; $i<count($emails); $i++)
{
    print $emails[$i][1]. "\n";
}

print "URLs:\n";
for($i=0; $i<count($urls); $i++)
{
    print $urls[$i][1]. "\n";
}

0
j2Author Commented:
ah, thats a tad overkill (but useful) :)

Let me rephrase the question, i want to

"take a string, and return a string with the urls/mails filtered out"

Im upping the points, since the above to is very useful code.
0
maxkirCommented:
Ouch, that's it then:

// Filtering emails ...
$string = ereg_replace("[[:alnum:]\.-]+@[[:alnum:]\.-]", "", $string );

// Filtering URLs
$string = ereg_replace("h?[f|t]tp://[-[:alnum:]\.=\?&/%]+", "", $string );
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

j2Author Commented:
Ah, thats the ticket. And this just replaces it with "nothing" right?

Totally great, by combining your examples i get exactly what i need.
0
maxkirCommented:
yes
0
j2Author Commented:
uhm the code in your firt suggestion gives me


Warning: Unknown option 't' in /home/sunrise/public_html/phptest/filtertest.php3 on line 7

whis is this line

preg_match_all("|(h?[f|t]tp://[\w-\.=\?&/%]+)|i", $string, $urls, PREG_SET_ORDER);

any comment?
0
maxkirCommented:
Change to this:

preg_match_all("#(h?[f|t]tp://[\w-\.=\?&/%]+)#i", $string, $urls,
                         PREG_SET_ORDER);
0
j2Author Commented:
excellent, thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.