Hi I want this URL: php.net/manual/en/function.explode.php to become php.net using php .. I tried with the explode fuction but couldnt get it to work ... list ($finalurl, $blabla) = explode('/', $url); PHP: Anyone have any tips? Thanks in advance
Try it out... http://ishoot.in/create/new.php exact code pasted here... <?php $url="php.net/manual/en/function.explode.php"; $new=explode('/',$url); echo $new[0]; ?> Code (markup):
To make explode work the way you're using it (returning the data into two variables) you need to add a third parameter to explode limiting the output to only two parts: list ($finalurl, $blabla) = explode('/', $url, 2); PHP:
That would require http:// before it whereas the OP's example suggests the $url doesn't start with http:// I guess that can be added though: <?php $url = 'php.net/manual/en/function.explode.php'; if (!preg_match('~^http://~i')) $url = 'http://'.$url; echo parse_url($url, PHP_URL_HOST); ?> PHP: