Hey peeps got a quick question, basically I am trying to strip the domain part from a url so the bit I am after would be "domain.com", I have wrote an expression to match it and it seems to work (havent thoroughly tested it).
When I output the $matches variable when testing on "http://www.yahoo.com" it only outputs www.y which I cant understand, any help is appreciated.
Here is the code I am using:
$domains = 'com|net|org|me|co|info|mobi|tv|us|biz|cm|co.uk|cc|ca|eu|tel|nu|in|aaa.pro|aca.pro|acct.pro|asia|avocat.pro|bz|ws|ac|am|at|bar.pro|be|br.com|cn|cn.com|co.nz|com.cn|com.co|com.mx|com.tw|cpa.pro|de|de.com|eng.pro|eu.com|fm|gs|hu.com|idv.tw|it|jp|jur.pro|kids.us|la|law.pro|me.uk|med.pro|ms|name|net.cn|net.co|nl|no.com|nom.co|org.cn|org.nz|org.tw|org.uk|pro|qc.com|recht.pro|ru.com|sa.com|se.com|se.net|sh|tc|tm|tw|uk.com|uk.net|us.com|uy.com|vg|za.com';
$domains = str_replace(".", "\.", $domains);
$pattern = '/[a-zA-Z0-9]{2,100}\.[' . $domains . ']/';
$test1 = "http://www.yahoo.com";
if(preg_match($pattern, $test1, $matches)) {
echo 'Test 1 is okay<br />';
echo $matches[0] . '<br />' . $matches[1] . '<br />' . $matches[0][0] . '<br />' . $matches[0][1] . '<Br />' . $matches[1][0] . '<br />' . $matches[1][1] . '<br />' . $matches[2][0] . '<br />' . $matches[2][1] . '<br />' . $matches[2][2];
}
This is my test code, it output the following:
Test 1 is okay
1
www.y
w
w