PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
shanehunter
Forum Commoner
Posts: 30 Joined: Sun Jun 27, 2010 3:43 pm
Post
by shanehunter » Mon Jul 12, 2010 11:19 am
Hey Guys,
So I have this code, it takes a
line from a text file and uses
that line as part of a post that it is scheduled to make via cron job to a website.
The code is ALMOST doing it's job - except for one thing - if the line contains an ampersand "&" then the line 'ends' there when brought back to the code.
ie:
http://www.billybobssite.com/user/profile=jmike&19428
becomes
http://www.billybobssite.com/user/profile=jmike
stripping the
&19428
Two things:
1. Why is it doing this?
2. How do I fix it?
=)
Code: Select all
function NextLine() {
$textfile = "links.txt";
if(file_exists($textfile)){
$sites = file($textfile, FILE_SKIP_EMPTY_LINES);
if(!empty($sites)) {
$string = array_shift($sites);
file_put_contents($textfile, implode($sites));
} else {
$string = "Empty";
}
} else {
$string = "Error";
};
return $string;
}
$s0 = NextLine();
echo "$s0";
shanehunter
Forum Commoner
Posts: 30 Joined: Sun Jun 27, 2010 3:43 pm
Post
by shanehunter » Mon Jul 12, 2010 12:08 pm
hey guys,
please help me out with this one.
Jade
Forum Regular
Posts: 908 Joined: Sun Dec 29, 2002 5:40 pm
Location: VA
Post
by Jade » Mon Jul 12, 2010 12:11 pm
You need to encode the string.
Code: Select all
function NextLine() {
$textfile = "links.txt";
if(file_exists($textfile)){
$sites = file($textfile, FILE_SKIP_EMPTY_LINES);
if(!empty($sites)) {
$string = array_shift($sites);
file_put_contents($textfile, implode($sites));
} else {
$string = "Empty";
}
} else {
$string = "Error";
};
return urlencode($string);
}
$s0 = NextLine();
echo "$s0";
shanehunter
Forum Commoner
Posts: 30 Joined: Sun Jun 27, 2010 3:43 pm
Post
by shanehunter » Mon Jul 12, 2010 12:12 pm
Jade,
Thank you! =)
As always, you prove to be VERY helpful to a PHP newb who's trying his hardest! =)
Jade
Forum Regular
Posts: 908 Joined: Sun Dec 29, 2002 5:40 pm
Location: VA
Post
by Jade » Mon Jul 12, 2010 12:14 pm
Haha well I've been there and done that so I completely understand the frustration.