Where to implement stripslashes?

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

Post Reply
User avatar
Fusioned
Forum Commoner
Posts: 32
Joined: Tue Jan 18, 2005 10:43 pm
Location: Philadelphia, PA

Where to implement stripslashes?

Post by Fusioned »

Below is the code for a little posting program I did. However of course, when the ' get's in there, the slashes come out. Where and how would I implement stripslashes()? Thanks. Im pretty bad at this stuff. :)

Code: Select all

<?

///WRITING TO THE FILE LEDGER.TXT


function WriteToFile ($Description, $Image, $EmailAddress, $FullName) &#123;

$TheFile = "ledger.txt";

$CurrentDate = date("l F j, Y");

$Open = fopen ($TheFile, "a");

if ($Open) &#123;

fwrite ($Open,
	"<table><tr><td width='400' valign='top'><font size='2' color='#333333'><b>$CurrentDate</b><BR>$Description</font></td></tr><tr><td width='400' valign='top'><font size='2' color='#333333'><u>$FullName</u> | <b><a href='mailto:$EmailAddress'>$EmailAddress</a></b><BR><BR>
	</font></td></tr></table><BR>\n");
		
	
		trim ($Description);
		
		fclose ($Open);
		
		$Worked = TRUE;
		
		&#125; else &#123;
		
		$Worked = FALSE;
		
		&#125;
		
		return $Worked;
		
		&#125; 
		
		if(isset($Array&#1111;'EmailAddress']))
		&#123;
		


$CallFunction = WriteToFile
($Array&#1111;"Description"], $Array&#1111;"Image"], $Array&#1111;"EmailAddress"], $Array&#1111;"FullName"]);



&#125;



if ($CallFunction)  &#123;

print ("\n");

 &#125; else &#123;
 
 print ("\n");
 
 &#125;
 ?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

wherever you want to print your unslashed output.

For example

Code: Select all

echo stripslashes($varname);
In your case, your going to have to escape quotes.. so it will look like

Code: Select all

echo "This is some text so ".stripslashes($varname)." and your good";
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Just an observation. You should shy away from <? as some servers may not allow the use of short tags. Use <?php and you will always be covered.
User avatar
Fusioned
Forum Commoner
Posts: 32
Joined: Tue Jan 18, 2005 10:43 pm
Location: Philadelphia, PA

Post by Fusioned »

Thanks. I usually do use ?php but I am lazy haha.

So you think I should do this?
Say I want to print a variable named $description out without slashes. Would I do this?

Code: Select all

"My name is Vince. I though that the movie was 'stripslashes($description)'.";
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Like this

Code: Select all

echo "My name is Vince. I though that the movie was '" . stripslashes($description) . "'.";
User avatar
Fusioned
Forum Commoner
Posts: 32
Joined: Tue Jan 18, 2005 10:43 pm
Location: Philadelphia, PA

Post by Fusioned »

Aha! It worked perfectly! Thank you so much guys.
Post Reply