Quotes in Text Boxes
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- kbrown3074
- Forum Contributor
- Posts: 119
- Joined: Thu Jul 20, 2006 1:36 pm
I have an Increadably simmular problem. I'm trying to take user input (textbox) and write it to a file. everytime I do, quotes (") and backslashes (\) get backslahes in front of them (\")(\\).
Then, later on, a php page opens that txt file (via include) and uses it as its content. (so I can quickly add 'whats new!' and such)
But we know what happens, my HTML gets very messed up. So what would I do to not write the backslashes in front of these things (I assume, based off of what I read here, they are called HTML Entities)?
EXAMPLE:
end EXAMPLE
*looks up hmtlentities() and html_entity_decode()*
Ah, so
Would write the $textboxString in a way that I could include it in a page and it would bring up that image?
Yes? No?
Then, later on, a php page opens that txt file (via include) and uses it as its content. (so I can quickly add 'whats new!' and such)
But we know what happens, my HTML gets very messed up. So what would I do to not write the backslashes in front of these things (I assume, based off of what I read here, they are called HTML Entities)?
EXAMPLE:
Code: Select all
$textboxString = <img src="images\test.jpg">;
#would be written to the file as:
<img src=\"images\\test.jpg\">*looks up hmtlentities() and html_entity_decode()*
Ah, so
Code: Select all
$textboxString = <img src="images\test.jpg">
fwrite(htmlentities($textboxString);Yes? No?
Alright.
Allow me to post the troubleing code.
Objectives Admin can log into a special site that will allow them to quickly change the Marquee text with out having to FTP a whole new, updated source.
source of the site using the marquee:
Now, the Admin Console
However, when I put something along the lines of <img src="images\smily.gif"> it writes it as <img src=\"images\\smily.gif\"> and html is unable to understand.
Also, when presented with the text box containing the contents of marquee.txt, I sometimes delete everything to start over. However, when I look at the marquee in action (and the marquee.txt file) I see that parts of the orginal file are still left.
So if the file was
and I selected all and deleted everything and wrote
I would get
This is puzzling me! I hope I have been thorough enough to be able to give any clues as to the solution to the problem.
Thank you very much for your time.
Allow me to post the troubleing code.
Objectives Admin can log into a special site that will allow them to quickly change the Marquee text with out having to FTP a whole new, updated source.
source of the site using the marquee:
Code: Select all
<?php
print("
<!-- The site...-->
<marquee scroll align=\"center\" loop=\"infinant\" bgcolor=\"black\" scrolldelay=\"1\" scrollamount=\"3\">
");
include 'marquee.txt';
print("
</marquee>
<!-- the rest of the site....-->Code: Select all
#admin has logged in, the following code is to open marquee.txt, fetch its contents, and display them in a textbox so the admin may edit the contents
$file = fopen('marquee.txt','r');
$marquee = fread($file, filesize('marquee.txt'));
fclose($file);
print("
<form method=\"post\" action=\"marqueeSubmit.php\">
<textarea name=\"marquee\" cols=\"125\" rows=\"50\"> $marquee </textarea>
<input type=\"submit\" value=\"submit marquee\">
</form>
");
#marqueeSubmit.php
$file = fopen('marquee.txt','r+');
fwrite($file, $marquee);
fclose($file);
print("
done <br />
<a href=\"siteWithMarquee.php\"> Test it out </a>
");Also, when presented with the text box containing the contents of marquee.txt, I sometimes delete everything to start over. However, when I look at the marquee in action (and the marquee.txt file) I see that parts of the orginal file are still left.
So if the file was
Code: Select all
Hello and welcome to my site!Code: Select all
PHP rocks!Code: Select all
PHP rocks!welcome to my site!Thank you very much for your time.
I did it!
Yes! I reviewd discussions in this thread and found that neither htmlentities() nor html_entity_decode() did what I wanted.
However, One thing proposed did stick out in my head, stripslashes(). I put it in and it worked perfectly!
Then I also thought of a solution to the characters being left over from from previous entries.
The solution was, of course, that I was writing with r+ and not w. ( I had thought that the slashes might be coming from certain properties of w, so I switched to r+ to test and I forgot to switch back)
Well, thank you for... writing things. You've helped me and solved a few headaches.

However, One thing proposed did stick out in my head, stripslashes(). I put it in and it worked perfectly!
Then I also thought of a solution to the characters being left over from from previous entries.
The solution was, of course, that I was writing with r+ and not w. ( I had thought that the slashes might be coming from certain properties of w, so I switched to r+ to test and I forgot to switch back)
Well, thank you for... writing things. You've helped me and solved a few headaches.
-
AngryPanda
- Forum Newbie
- Posts: 16
- Joined: Wed Jul 19, 2006 12:18 am