[thelist] Stripping characters from string

R.Livsey R.Livsey at cache-22.co.uk
Sun Apr 28 11:55:01 CDT 2002


> Hello all,
>
> Does anyone have any PHP snippets of code that will strip several
> characters from a string? I am trying to figure out how to do
> this without
> using 3 different if statement blocks. This is what I am looking for.
>
> ie....User email address is "Chris Ditty"
> <mail at redhotsweeps.com> or Chris
> Ditty <mail at redhotsweeps.com>
>
> I need to be able to strip the quotes and everything between
> them and the
> < > signs from the first one and then the name and the < >
> signs from the
> second.
> Does anyone know how to do this quickly and easily?
>
> Thanks
> CDitty


Are you just trying to grab the email addresses from the string?

The following code should take the email address and put it into $store,
which is an array containing all the matches [anything inbetween the
parentheses]).


$regex = "([A-Z0-9\.\-]+@[A-Z0-9\.\-]+\.[A-Z\.]+)";
$string = "Chris Ditty <mail at redhotsweeps.com>";

eregi($regex, $string, $store);


Then you can use $store as you please.

Theres more detail on ereg/eregi over at php.net
(http://www.php.net/manual/en/function.ereg.php).

Oh and use a better regex if you like, that was just one I had lying
around :o)

hth

R.Livsey
Web Developer
[ PHP | Perl | mySQL | Java ]
w : cache-22.co.uk
e : R.Livsey at cache-22.co.uk




More information about the thelist mailing list