Jump to content

Recommended Posts

quick question. as i've explained previously i have a query with two potential results

 

$link1 = ('http://www.cheapsmells.com/index.asp?ref=webgains&siteid=20592');
$link2 = ('http://track.webgains.com/click.html?wgcampaignid=20592&wgprogramid=222&wgtarget=http://www.cheapsmells.com/');

 

$link1 will always relate to the following kind of result:

 

http://www.cheapsmells.com/viewProduct.php?id=5098

 

and $link2 to this one:

 

http://track.webgains.com/click.html?wgcampaignid=20592&wgprogramid=222&wgtarget=http://www.cheapsmells.com/product_show_new.asp?id=5098

 

i am using the code, kindly provided by someone on the forum:

 

if ($row['sto_link'] == $link1){
$code = $row['buy_link'];
$temp = parse_url($code);
$temp2 = parse_str($temp['query'],$parsed_code);
$new_id = explode('/',$parsed_code['id']);
$new_code = 'http://www.awin1.com/awclick.php?awinmid=911&awinaffid=74040&p=http://www.cheapsmells.com/viewProduct.php?id='.$new_id[0];

echo '<a href="'.$new_code.'" target="_new">';
echo '<img alt="BUY" height="15" src="/BUY.gif" target="_new" width="50" /></a>';
}

 

to lift the "id" from the two potential results. the problem with the 2nd ($link2) is that it is a much more complex filepath and the "id" does not come after the first "?" in the path.

 

hence why i can't get my elseif statement:

 

elseif ($row['sto_link'] == $link2){
$code = $row['buy_link'];
$temp = parse_url($code);
$temp2 = parse_str($temp['query'],$parsed_code);
$new_id = explode('/',$parsed_code['asp?id']);
$new_code = 'http://www.awin1.com/awclick.php?awinmid=911&awinaffid=74040&p=http://www.cheapsmells.com/viewProduct.php?id='.$new_id[0];

echo '<a href="'.$new_code.'" target="_new">';
echo '<img alt="BUY" height="15" src="/BUY.gif" target="_new" width="50" /></a>';
}

 

to work. how can i resolve this?

 

many thanks!

Link to comment
https://forums.phpfreaks.com/topic/73006-solved-parse_url-query/
Share on other sites

If id=XXXXXX is always at the end of the url you can use the preg_match as follow:-

<?php
$link = 'http://www.cheapsmells.com/viewProduct.php?id=5098';
preg_match('/id=(\d+)$/', $link, $match);
echo $match[1]; //5098

$link = 'http://track.webgains.com/click.html?wgcampaignid=20592&wgprogramid=222&wgtarget=http://www.cheapsmells.com/product_show_new.asp?id=5098';
preg_match('/id=(\d+)$/', $link, $match);
echo $match[1]; //5098
?>

 

 

 

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.