Like http:webmail.wipro.com#a:?b;
I want to break this url and store only webmail and wipro into my database. Can any one help me out with this please. Using php.
Like http:webmail.wipro.com#a:?b;
I want to break this url and store only webmail and wipro into my database. Can any one help me out with this please. Using php.
You should use the parse_url function to retrieve the parts and then use at your will (in your case, saving them in database).
Here is a test code/output from the manual:
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
Prints the following:
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
/path
You should use regular expressions. If you run something like
preg_match('http:(.*?).(.*?).com#a:?b;', 'http:webmail.wipro.com#a:?b;', $matches);
$matches[1] should say webmail and $matches[2] should contain wipro.
There is more documentation for regexes and preg_match on the PHP site.
It sounds like what you're looking for is to recognise any words at all within the URL. In this case, try this RegExp:
preg_match_all ('/\b(\w{4,})\b/', $url, $matches);
$matches
will contain an array of all word-like strings of length 4 or more