Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem 4. Extract all valid URLs
- //Write a regex pattern for extracting all URL’s addresses from given text.
- //Hint: http://en.wikipedia.org/wiki/Uniform_resource_locator
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <form method="post" action="ExtractValidURLS.php">
- <input type="text" name="str1">
- <input type="submit" value="GO">
- </form>
- </body>
- </html>
- <?php
- $string = $_POST['str1'];//"Hello https://www.bytes.com world ftp://www.yahoo.com http://www.yahoo.com/asd/asd";
- preg_match_all('/((([A-Za-z]{3,9}:(?:\/\/)?)'
- . '(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-'
- . ']+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za'
- . '-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?'
- . '\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*'
- . '))?)/', $string, $text);
- echo '<pre>' . print_r($text[0], true) . '</pre>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment