phpcodec Posted December 29, 2008 Share Posted December 29, 2008 Hi, i am having problems writing a regex script that will take a string of text with hyperlinks in and extracting just the hyperlinks I have made several attempts and so far failed can someone help? Quote Link to comment https://forums.phpfreaks.com/topic/138781-php-urls/ Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 Post your code plz. Quote Link to comment https://forums.phpfreaks.com/topic/138781-php-urls/#findComment-725633 Share on other sites More sharing options...
phpcodec Posted December 29, 2008 Author Share Posted December 29, 2008 Here is the code i use $string = 'this is a test <a href="www.iwanturl.com">I want URLS</a> this is a test'; echo preg_replace('/^<a href="[-:_.\/a-zA-Z0-9]+">[-:_.\/a-zA-Z0-9]+<\/a>/','',$string); Quote Link to comment https://forums.phpfreaks.com/topic/138781-php-urls/#findComment-725637 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 /a href="?([:\/\w\s\d\.]*)"?/ Quote Link to comment https://forums.phpfreaks.com/topic/138781-php-urls/#findComment-725640 Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 <?php $subject = 'this is a test <a href="www.iwanturl.com">I want URLS</a> this is a test'; $pattern = '/a href="?([:\/\w\s\d\.]*)"?/i'; preg_match($pattern, $subject, $matches); print_r($matches); ?> Quote Link to comment https://forums.phpfreaks.com/topic/138781-php-urls/#findComment-725642 Share on other sites More sharing options...
phpcodec Posted December 29, 2008 Author Share Posted December 29, 2008 It works but it doesnt work if their is multiple hyperlinks in the string Quote Link to comment https://forums.phpfreaks.com/topic/138781-php-urls/#findComment-725646 Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 <?php $subject = 'this is a test <a href="www.iwanturl.com">I want URLS</a> this is a test'; $pattern = '/a href="?([:\/\w\s\d\.]*)"?/i'; preg_match_all($pattern, $subject, $matches); print_r($matches); ?> Quote Link to comment https://forums.phpfreaks.com/topic/138781-php-urls/#findComment-725656 Share on other sites More sharing options...
phpcodec Posted December 29, 2008 Author Share Posted December 29, 2008 Excellent, but still one more problem instead of getting the full url like this "downloadfile.php?file=xxx.zip" it just gets "downloadfile.php" Quote Link to comment https://forums.phpfreaks.com/topic/138781-php-urls/#findComment-725666 Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 You should ask this question in the regex forum, they can offer better help there. Quote Link to comment https://forums.phpfreaks.com/topic/138781-php-urls/#findComment-725673 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 Yes, please just mark this as solved and start a new thread in the Regex section with what you have. Quote Link to comment https://forums.phpfreaks.com/topic/138781-php-urls/#findComment-725675 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.