Solved

Script puts slashes after posting form

Posted on 2002-03-19
16
296 Views
Last Modified: 2010-05-18
Hello,

I have a php script (thanks to dkjariwala for help b4 ;) , that does what I want but it puts slashes/doesn't show some characters when you post.

Here is my sample page http://only.host.sk/sample_pk_list.html

Here is where you post to the list http://only.host.sk/sample_post_pk.html

Here is the script code http://only.host.sk/pklist_sk.txt

You can test out the page and post any kind of stuff you want to see what I mean.

Questions:

1) How do I prevent the slashes, fix missing symbols?

2) When I view the source, why is there suddenly huge gaps/spaces in the code, except for the new entries?

Thanks for you help.
0
Comment
Question by:sayhi
  • 8
  • 6
  • 2
16 Comments
 
LVL 5

Expert Comment

by:andriv
ID: 6881280
The links above do not work but I believe the symbols are missing because of the slashes.  You can remove the slashes by using the stripcslashes(text) function:

Example:

$mystring = 'This is a "string"';

stripcslashes($mystring);

2) may be solved with the above but since I cannot get to the links it's hard to determin what is causing it.

0
 
LVL 1

Author Comment

by:sayhi
ID: 6881503
doh the host went down
0
 
LVL 1

Author Comment

by:sayhi
ID: 6881506
erm, maintenance on the 19th, hopefully be back up tomorrow
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 5

Expert Comment

by:dkjariwala
ID: 6881745
You would have to store the returned value of stripcslashes somewhere otherwise statements,

$mystring = 'This is a "string"';

stripcslashes($mystring);

Wont do *anything*.

Do it like

$mystring = 'This is a "string"';

$new_string = stripslashes($mystring);

Also, the link you gave is giving error so cant say much about second problem.

JD
0
 
LVL 5

Expert Comment

by:andriv
ID: 6881783
Not all true, you do not need to store it because you can use it in a query, use it when writing to a file or send it to the browser:

print(stripcslashes($mystring));

As long your using it immediately you do not need to store it in a variable.
0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 6881885
Yeah but you didn't print it or used it any other way, and that was my point.

JD
0
 
LVL 1

Author Comment

by:sayhi
ID: 6884302
hi guys, too bad my host hasn't finished maintenance =\

well, if they don't come back up. here is where a form of my script is at http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=php&qid=20275170


for the slashes thing, say they put this in one of the boxes: "i don't know". on the list page it will post as "i don\'t know"


for the code gaps, you oughta see the list page to see what i mean. though the page shows up fine.


Also, on March 21st I'm gonna be going to Hawaii for my Spring Break =). So I'll be gone for a week, to let ya know.
0
 
LVL 5

Expert Comment

by:andriv
ID: 6884465
I don't know the exact functions and variables you are using in PHP but it will look similar to what follows:

fputs($myfile,stripcslashes($classtype)."<br>");

$myfile is the link you created for the actual file.

0
 
LVL 1

Author Comment

by:sayhi
ID: 6884507
ok, i'll see what I can do tonight before I pack my stuff
0
 
LVL 1

Author Comment

by:sayhi
ID: 6884664
okay guys, my host is backup, the links should work now... (i hope)
0
 
LVL 5

Expert Comment

by:andriv
ID: 6884702
Yes, you will need the stripcslashes($classtype):

foreach($lines_array as $line)
{
     fwrite($fp,stripcslashes($line) . $CRLF); //write original lines as it is.
     if(eregi('\<\!--data--\>',$line)) // if line stats its a place where data is stored
     {        
     fwrite($fp,"<table width=\"70%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">". $CRLF);
     fwrite($fp,"<tr><td>".$CRLF);  //write out new entry.
     fwrite($fp,"<font size=\"-1\" face=\"Verdana, Arial, Helvetica, sans-serif\">". $CRLF);
     fwrite($fp,"<b>Believed to be <font color=red>". "stripcslashes($danger) . "</font></b> <BR>" . $CRLF);
     fwrite($fp,"<b>Last seen on:</b>" . stripcslashes($lastseen) . "<BR>" . $CRLF);
     fwrite($fp,"<b>Name:</b>" . stripcslashes($pkname). "($pkacct) <BR>" . $CRLF);
     fwrite($fp,"<b>Level:</b>" . stripcslashes($pklvl) . "<BR>".$CRLF);  
     fwrite($fp,"<b>Class:</b>" . stripcslashes($classtype) . "<BR>".$CRLF);
     fwrite($fp,"<b>Explaination:</b>" . stripcslashes($explain) . "<BR>". $CRLF);
     fwrite($fp,"<font color=white><b>Submitted by: " . stripcslashes($myname) . "($myacct)</b></font><BR>" . $CRLF);
     fwrite($fp,"</font> <BR>" . $CRLF);
     fwrite($fp,"</td></tr></table> <BR>" . $CRLF);
     }

}
0
 
LVL 1

Author Comment

by:sayhi
ID: 6884716
hmm, didn't work
0
 
LVL 1

Author Comment

by:sayhi
ID: 6884721
oh yeah, when i view source now on the list page, there are now gigantic spaces in the code. wow
0
 
LVL 5

Expert Comment

by:andriv
ID: 6884736
To remove the spaces change the following line:

$CRLF = "\r\n"; //keep it "\r\n" if on unix/linux. original is "\n"

To:

$CRLF = "\n"; //keep it "\r\n" if on unix/linux. original is "\n"

remove the \r.

did it correct the slash problem?
0
 
LVL 5

Accepted Solution

by:
andriv earned 50 total points
ID: 6884743
I gave you the wrong function for striping the slashes, remove the 'c' from it.

stripslashes
0
 
LVL 1

Author Comment

by:sayhi
ID: 6885346
ah ha. thx.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question