Jump to content

How to validate a specific hyperlink from different links using php


compphp

Recommended Posts

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..

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*

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.