Jump to content

[SOLVED] replace


shage

Recommended Posts

$refcode=$_GET['refcode'];

$sitelink=str_replace("#refcode#",$refcode,$sitelink);

<link>'.$site_link.'</link>

 

Im trying to pull refcode from url and have it replace all instance of #refcode# on page, for some reason its not doing that.

Link to comment
Share on other sites

well in your example you set $sitelink then when you refer to it as $site_link. That might just be a typo for this post, but might not be. I know I've spent ages before because of something like that :/

 

I use the str_replace for someone similar for some of my code

 

/*
$row2["c_url2"] is a result from a mysql query
example output is "http://example.com/archive/#yyyy#"
where I want "http://example.com/archive/2007" 
*/

$row2["c_url2"] = str_replace("#yyyy#",date('Y'),$row2["c_url2"]);

echo $row2["c_url2"];

 

What errors are you getting from your code?

 

Link to comment
Share on other sites

$sitelink=str_replace("#refcode#",$refcode,$sitelink,$site_link)

 

what this is telling is that the sitelink is a text box that is in mysql which it pulls perfect, just doenst replace the refcode in the url with the username. The site_link is another link such as % of payout, it will random that this link which is up top of the page might be 30% revshare and the bottom links might be set to be 60% refshare, is why both have that name

hope that makes sense

Link to comment
Share on other sites

<?php
//include database stuff
include('config.php');

if(!isset($_GET['site_id']))
{
die("You did not provide any site id");
}

//site get variables
$siteid=addslashes($_GET['site_id']);
$piclimit=$_GET['pic_limit'];
if(!isset($_GET['pic_limit']))
{
$piclimit=3;
}
$flavor=addslashes($_GET['flavor']);
if((!isset($_GET['flavor']))||(($_GET['flavor']!="h")&&($_GET['flavor']!="s")))
{
$flavor='s';
}
$refcode=$_GET['refcode'];
$link=$_GET['link'];

//query from table site
$query="SELECT * FROM site WHERE site_id=$siteid";
$res1=mysql_query($query);
$site=mysql_fetch_array($res1);
if($_GET['link']=="tour")
{
$sitelink=$site['tour'];
}
else if ($_GET['link']=="gallery") {

$sitelink=$site['gallery'];
}
else {
$sitelink=$site['site_link'];
}

//replace refcode
$sitelink=str_replace("#refcode#",$refcode,$sitelink);

//query from table content
$query="SELECT * FROM groups WHERE site_id=$siteid AND label='$flavor'";
$res2=mysql_query($query);
$i=0;
while($group=mysql_fetch_array($res2))
{
$group_sn[$i]=$group['sn'];
$group_folder[$i]=$group['folder_name'];
$i++;
}

//randomize
$max=count($group_sn);
$max-=1;
$random=rand(0,$max);
$randfolder=$group_folder[$random];
$randsn=$group_sn[$random];


$folder=$randfolder;
//query from table groups
$query="SELECT * FROM content WHERE sgroup='".$randsn."'";
$res3=mysql_query($query);

while($content=mysql_fetch_array($res3))
{
$content_title[]=$content['title'];
$content_body[]=$content['body'];
}

$max=count($content_title);
$max-=1;
$random=rand(0,$max);

$randtitle=stripslashes($content_title[$random]);

$max=count($content_body);
$max-=1;
$random=rand(0,$max);
$randbody=$content_body[$random];

$s1=array("#link#","#tlink#","#glink");
$s2=array($site['site_link'],$site['tour'],$site['gallery']);
$randbody=str_replace($s1,$s2,$randbody);

if(!isset($folder))
{
die('Unable to get folder contents.');
}
//read folder contents
$myDirectory = opendir($folder.'/');
while($entryName = readdir($myDirectory)) {
if(($entryName!=".")&&($entryName!=".."))
$dirArray[] = $entryName;
}
closedir($myDirectory);
sort($dirArray);

$indexCount	= count($dirArray);

$max=count($dirArray)-$piclimit;
$random=rand(0,$max);




for($a=0;$a<$piclimit;$a++)
{
$tstring.='<center><a href="'.$sitelink.'">'.'<img src="'.$folder.'/'.$dirArray[$random].'" border="0"></a>  ';
$random++;
}

$site_link=$site['site_link'];

$time=getdate();


//my special bracket randomizer algorithm
$body=$randbody;
$body = explode('(', $body);
$out = $body[0];
for ($i = 1; $i < count($body); $i++){
$con = explode(')',$body[$i]);
$pos = explode(',', $con[0]);
$out .= $pos[rand(0, count($pos)-1)]. $con[1];
}
$randbody=stripslashes($out);

//cdat will be made with two variables, picsarranged and randbody
$cdat=$tstring."<br/>".$randbody;

//generate the feed
$disp='<rss version="2.0"
   xmlns:content="http://purl.org/rss/1.0/modules/content/">
   <channel>

      <title>'.$randtitle.'</title>
      <link>'.$site_link.'</link>
      <description>'.$site_desc.'</description>
      <language>en-us</language>

      <copyright>Copyright '.$time['year'].', rssbuilders</copyright>


      <item>
         <title>'.$randtitle.'</title>
         <link>'.$site_link.'</link>
         <description><![CDATA[ '.$cdat.' ]]></description>
         <category>Feeds</category>

         <content:encoded><![CDATA[ '.$cdat.' ]]></content:encoded>
         <guid isPermaLink="true">'.$site_link.'</guid>
      </item>


   </channel>
</rss>';

echo $disp;
?>

 

Thats the code for the file, i cant figure out why it dont replace all #refcode#

Link to comment
Share on other sites

Maybe echo/print out all the vars used in the str_replace before using them, just to make sure they even contain what you'd expect them to. Is error reporting on? (Maybe you have one and don't know it).

Also, the 4th parameter in str_replace is for a var to be passed by reference and will hold the "count" of how many times the search string was found and replaced. You're not using it in your code, but so you know for future reference.

Otherwise, I don't see a problem in the way str_replace is being used.

 

Link to comment
Share on other sites

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.