Jump to content


Photo

a problem with preg_match


  • Please log in to reply
1 reply to this topic

#1 catzilla

catzilla
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 31 May 2006 - 10:23 AM

why $output[2] = "yahoo-inc.c" instead of "yahoo-inc.com" ? thanks for answer in advance

<?php

$mail = "cc.yahoo-inc.com";
preg_match('/(\w+\.*\w+\.)([\w|\-]+\.[aero|biz|cat|com|coop|info|jobs|mobi|museum|name|net|org|pro|travel|gov|edu|int])/i',$mail,$output);
print_r($output);

?>

# php tr7.php
Array
(
[0] => cc.yahoo-inc.c
[1] => cc.
[2] => yahoo-inc.c
)

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 31 May 2006 - 03:13 PM

<?php

$mail = "cc.yahoo-inc.com";
preg_match('/(\w+\.*\w+\.)([\w|\-]+\.(aero|biz|cat|com|coop|info|jobs|mobi|museum|name|net|org|pro|travel|gov|edu|int))/i',$mail,$output);

print_r($output);

?>

Should output:

Array
(
    [0] => cc.yahoo-inc.com
    [1] => cc.
    [2] => yahoo-inc.com
    [3] => com
)

~ D Kuang




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users