Solved

Script puts slashes after posting form

Posted on 2002-03-19
16
289 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
Comment Utility
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
Comment Utility
doh the host went down
0
 
LVL 1

Author Comment

by:sayhi
Comment Utility
erm, maintenance on the 19th, hopefully be back up tomorrow
0
 
LVL 5

Expert Comment

by:dkjariwala
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

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

Author Comment

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

Expert Comment

by:andriv
Comment Utility
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
Comment Utility
hmm, didn't work
0
 
LVL 1

Author Comment

by:sayhi
Comment Utility
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
Comment Utility
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
Comment Utility
I gave you the wrong function for striping the slashes, remove the 'c' from it.

stripslashes
0
 
LVL 1

Author Comment

by:sayhi
Comment Utility
ah ha. thx.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now