Jump to content

How to validate a specific hyperlink from different links using php


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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