Problem: Extraction anything between http://www. and .com OR http:// & .com.
Solution:
<?php
$url1='http://www.examplehotel.com';
//$url2='http://test-hotel-1.com';
$pattern='@^http://([^/]+).com@i';
preg_match($pattern, $url1, $matches);
print_r($matches);
?>
When $url1 is matched it should return string ‘examplehotel’
when $url2 is matched it should return string ‘test-hotel-1’
It works correctly for $url2 but empty for $url1….
In my pattern I want to add [http://] or [http://www.] I added (http://)+(www.)+ but the match returns are not expected :(.
May I know where I am going wrong?
try this one:
or in your pattern you just need to make
wwwoptional (may or may not appear in pattern):