0

For several hours I'm trying to ride my fair one script and end up almost ready, but it gets weird problem.

Attach a piece of code to get an idea what I mean.

$sep = '\.com|\.tv';
$string = 'sub.sub2.sub3.tv-bole-el.com';
$pat = '~[-[:alnum:]]{2,}\b('.$sep.')\b~i';

preg_match_all($pat, $string, $matches, PREG_PATTERN_ORDER);

In this case in array $matches, it would be correct if you spend tv-bole-el.com

Instead, I earned 2 domains:

  • sub3.tv
  • -bole-el.com

Anybody have an idea where is wrong?

1 Answers1

0

Not sure if this is what you need but this worked for me:

$sep = '\.com|\.tv';
$string = 'sub.sub2.sub3.tv-bole-el.com';
$pat = '~[-[:alnum:]]{2,}\b('.$sep.')$~i';
preg_match_all($pat, $string, $matches, PREG_PATTERN_ORDER);

var_dump($matches[0]);

OUTPUT:

array(1) {
  [0]=>
  string(14) "tv-bole-el.com"
}
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I try it, but after put: $string='subdomain1.subdomain2.subdomain3.tv-a-borla.com 7days.com'; Output its: [0] => Array ( [0] => 7days.com ) [1] => Array ( [0] => .com ) – Andon Ivanov Nov 14 '13 at 11:05