Clarification:
So really, what you want to achieve is to ONLY have the email address?

I'm POSITIVE there's a better way with ereg_replace(), but I haven't got
time to experiment, and i'm no expert :)

So, what I figured was that you would loop through the $email, and if the
first char wasn't a "<", strip it out:

"Chris Ditty" <[EMAIL PROTECTED]>
Chris Ditty" <[EMAIL PROTECTED]>
hris Ditty" <[EMAIL PROTECTED]>
ris Ditty" <[EMAIL PROTECTED]>
is Ditty" <[EMAIL PROTECTED]>
...
<[EMAIL PROTECTED]>


You're then left with "<something".  Assuming all your address' are wrapped
in < ... >, you'll now have <[EMAIL PROTECTED]>.

Then, you want to strip out the leading < and the trailing > only (this
means weird email address' which have a < or > in them won't break.

You should now have [EMAIL PROTECTED]


UNTESTED code:

<?
$email = '"Chris Ditty" <mail@redh>otsweeps.com>';

while (!eregi('^<', $email))
    {
    $email = substr($email, 1);
    //echo htmlspecialchars($email)."<BR>";
    }
$email = ereg_replace("^<", "", $email);
$email = ereg_replace(">$", "", $email);

echo htmlspecialchars($email)."<BR>";
?>


Like I said, this is probably NOT the best solution, just *a* solution, but
it should work.  It's independent of the "'s you had in there... all it
cares about is $email ending with "<something>", getting rid of the
preceeding it, and then getting rid of the <>'s that wrap it.

You might also like to get rid of anything trailing the >.

Uncomment line 6 to watch the progress of the while loop :)


Justin French
--------------------
Creative Director
http://Indent.com.au
--------------------



on 28/04/02 4:16 PM, CDitty ([EMAIL PROTECTED]) wrote:

> Hello all,
> 
> Does anyone have any 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"
> <[EMAIL PROTECTED]>  or  Chris Ditty <[EMAIL PROTECTED]>
> 
> 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
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to