Jump to content

Preg_match a link?


Recommended Posts



I'm looking to preg_match a link from another website, I want to match it because the actual link changes at random times, so I want to header redirect the returned link so it works regardless of any changes,


In the source of the website, the block I need to copy is:




<a style="margin: 5px 5px 5px 5px; background: url(/images/buttons/continue2.png) no-repeat; display: block; text-indent: -40000px; width: 110px; height: 37px;" href="i need to copy the link found in this box" target="_blank" >Continue</a> 

This area of the source seems to be unique so it wouldn't collide with any other code.


Thank you

Link to comment
Share on other sites

Here's something I used to use longgggg ago if you want it, its not preg_match but it gets the job done.


function get_string_between($string, $start, $end) {
     $string = " ".$string;
     $ini = strpos($string,$start);
     if ($ini == 0)
          return "";
     $ini += strlen($start);
     $len = strpos($string,$end,$ini) - $ini;
     return substr($string,$ini,$len);


$curl= curl_init();
curl_setopt($curl, CURLOPT_URL, '(PUT YOUR LINK HERE)';
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($curl); 
$Info = get_string_between($data, '<span>', '</span>');
Link to comment
Share on other sites

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

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

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.