# Substr() and preg\_match()

**URL:** <https://forum.kirupa.com/t/substr-and-preg-match/38589>\
**Category:** Uncategorized\
**Created:** [December 26, 2003, 5:56am UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589 "2003-12-26T05:56:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamza84](https://avatars.discourse-cdn.com/v4/letter/h/ea5d25/32.png) [@hamza84](https://forum.kirupa.com/u/hamza84)\
**Post date:** [December 26, 2003, 5:56am UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589/1 "2003-12-26T05:56:20Z")

</div>

I can’t understand how to use either of these functions in PHP. Bother to help anybody?

---

<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:** [December 26, 2003, 6:39am UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589/2 "2003-12-26T06:39:33Z")

</div>

whatchya trying to do exactly? can you be more specific?

[http://www.php.net/preg\_match](http://www.php.net/preg_match)  
[http://www.php.net/substr](http://www.php.net/substr)

---

<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:** [December 26, 2003, 5:29pm UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589/3 "2003-12-26T17:29:37Z")

</div>

I actually understood the substr function. I’m trying to use preg\_match() for checking an email format.

---

<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:** [December 26, 2003, 5:43pm UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589/4 "2003-12-26T17:43:21Z")

</div>

```php
<?php

$email = "JohnSmith@Site.com";

if ( !preg_match("/^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/", $email ) )
echo 'E-mail is invalid!';

?>

```

I got the regex pattern off a site i googled up, I’m too dumb to write my own, lol…

---

<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:** [December 26, 2003, 6:31pm UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589/5 "2003-12-26T18:31:38Z")

</div>

those kind of things scares 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:** [December 26, 2003, 8:23pm UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589/6 "2003-12-26T20:23:41Z")

</div>

haha! well, mind explaining it a bit ahmed?

---

<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:** [December 27, 2003, 2:47am UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589/7 "2003-12-27T02:47:48Z")

</div>

He got it off a site…

Basically it’s a pattern of symbols :

("/^w(?:w|-|.(?!.|@))_@w(?:w|-|.(?!.))_.w{2,3}/

Well Duh… But the symbols can mean different things… The ? marks with a : next to it I believe are conditional statments set inside of a list of patterns…I know that the w represents an escape sequence that draws forth from the current locale computer’s character map.

But… Most of the othger symbols draw a blank for me… And I’m not quite sure I want to look it up to figure it out right now 😉

---

<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:** [December 27, 2003, 4:29am UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589/8 "2003-12-27T04:29:30Z")

</div>

I wish things were more clear

---

<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:** [December 27, 2003, 3:08pm UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589/9 "2003-12-27T15:08:31Z")

</div>

well they are called regular expressions and they are a bit difficult to understand at first… here is a link to a really good tutorial about using them…  
[http://www.tote-taste.de/X-Project/regex/index.php](http://www.tote-taste.de/X-Project/regex/index.php)

---

<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:** [December 27, 2003, 7:39pm UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589/10 "2003-12-27T19:39:16Z")

</div>

hey thanks jubba! I got more than I needed. Ain’t that some christmas present eh? 😃

---

<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:** [December 29, 2003, 5:08am UTC](https://forum.kirupa.com/t/substr-and-preg-match/38589/11 "2003-12-29T05:08:27Z")

</div>

Hot \*\*\*\*… Pretty good link there Vash 🙂 I knew some commands but now I know em all! 😃

“/^[-\_a-z0-9]+(.[-\_a-z0-9]+)_@[-a-z0-9]+(.[-a-z0-9]+)_.[a-z]{2,6}$/i”

There ya go 😃 That’s great!
