Re: Stripping characters.....
| From: | Justin French | Date: | Sun, 28 Apr 2002 07:12:51 +0000 |
| Subject: | Re: Stripping characters..... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-94969@lists.php.net to get a copy of this message | ||
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" <mail@redhotsweeps.com>
Chris Ditty" <mail@redhotsweeps.com>
hris Ditty" <mail@redhotsweeps.com>
ris Ditty" <mail@redhotsweeps.com>
is Ditty" <mail@redhotsweeps.com>
...
<mail@redhotsweeps.com>
You're then left with "<something". Assuming all your address' are wrapped
in < ... >, you'll now have <mail@redhotsweeps.com>.
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 mail@redhotsweeps.com
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 (mail@redhotsweeps.com) 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"
> <mail@redhotsweeps.com> or Chris Ditty <mail@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
>