compphp Posted March 2, 2012 Share Posted March 2, 2012 can you please tell me how to validate a specific hyperlink from different hyperlinks. eg i want to fetch these links separately starting with the bolded address from a website using simple html dom 1 http://www.website1.com/1/2/ 2 http://news.website2.com/s/d 3 http://website3.com/news/gds i know we can do it using preg_match ;but i am getting a hardtime understanding preg_match. can anyone give me a preg_match script for these websites validation.. and also if possible please explain.. Quote Link to comment https://forums.phpfreaks.com/topic/258105-how-to-validate-a-specific-hyperlink-from-different-links-using-php/ Share on other sites More sharing options...
AyKay47 Posted March 2, 2012 Share Posted March 2, 2012 Depending on the context, you may be better off using string functions for this. $str = "some text http://www.test.com/qs"; $start_pos = strpos($str,"http://"); $end_pos = strpos($str,"/",$start_pos + 1); $substring = substr($str,$start_pos,$end_pos); *untested* Quote Link to comment https://forums.phpfreaks.com/topic/258105-how-to-validate-a-specific-hyperlink-from-different-links-using-php/#findComment-1323082 Share on other sites More sharing options...
requinix Posted March 2, 2012 Share Posted March 2, 2012 Doesn't account for the length of the "http://" itself, and the third parameter to substr() is the length of the substring. More like $str = "some text http://www.test.com/qs"; $start_pos = strpos($str,"http://"); $end_pos = strpos($str, "/", $start_pos + 7); $substring = substr($str, $start_pos, $end_pos - $start_pos - 1); Could still use some error checking though. Quote Link to comment https://forums.phpfreaks.com/topic/258105-how-to-validate-a-specific-hyperlink-from-different-links-using-php/#findComment-1323108 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.