e1seix Posted October 12, 2007 Share Posted October 12, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/73006-solved-parse_url-query/ Share on other sites More sharing options...
esukf Posted October 12, 2007 Share Posted October 12, 2007 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/73006-solved-parse_url-query/#findComment-368175 Share on other sites More sharing options...
e1seix Posted October 12, 2007 Author Share Posted October 12, 2007 how exactly do i impliment that into if statement above? many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/73006-solved-parse_url-query/#findComment-368200 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.