# ereg\_replace bug?

**URL:** <https://forum.kirupa.com/t/ereg-replace-bug/34574>\
**Category:** programming\
**Created:** [November 4, 2003, 3:22am UTC](https://forum.kirupa.com/t/ereg-replace-bug/34574 "2003-11-04T03:22:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![comicGeek](https://avatars.discourse-cdn.com/v4/letter/c/90db22/32.png) [@comicGeek](https://forum.kirupa.com/u/comicGeek)\
**Post date:** [November 4, 2003, 3:22am UTC](https://forum.kirupa.com/t/ereg-replace-bug/34574/1 "2003-11-04T03:22:18Z")

</div>

I am making a Flash/PHP Guestbook! I have successfully done so but the automatic parsing of emails and urls have some problems! I am using ereg\_replace() to search for and parse urls and email address but when a user has an email like [some\_guy@someguys.com](mailto:some_guy@someguys.com) it only considers the part after the underscore thus displaying the wrong email address: in this case would be [guy@someguys.com](mailto:guy@someguys.com)!

Here’s the script I used!

```php

$link = ereg_replace("[[:alpha:]]+@[^<>[:space:]]+
[[:alnum:]]","<a href=\"mailto:\\0\"><u>".$name."</u></a>", $link);

```

Hope you can help me!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 4, 2003, 9:30am UTC](https://forum.kirupa.com/t/ereg-replace-bug/34574/2 "2003-11-04T09:30:11Z")

</div>

Thanks for all who thought of a way to help. 😃 I managed to solve the problem!

Instead of using:

```php

$link = ereg_replace("[[:alpha:]]+@[^<>[:space:]]+
[[:alnum:]]","<a href=\"mailto:\0\"><u>".$name."</u></a>", $link);

```

I replaced it with:

```php

$link = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.
([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<u><A HREF=\"mailto:
$1\">".$name."</A></u>",$link);

```
