![]() |
some php bits i want to do asp
how can i do this in asp?
function cleanString($string) { $string = trim($string); // same as in asp $string = htmlentities($string, ENT_QUOTES); // takes all the html tags and quotes and makes them specials chars $string = addslashes($string); // adds slashes so it wont mess up php $string = nl2br($string); // adds a <br> to all the returns that a user puts in a field return($string); } |
Hmmm... try this:
function cleanString($string) { $string = trim($string); // same as in asp $string = htmlentities($string, ENT_QUOTES); // takes all the html tags and quotes and makes them specials chars $string = addslashes($string); // adds slashes so it wont mess up php $string = nl2br($string); // adds a <br> to all the returns that a user puts in a field return($string); } Literally: <% Function CleanString(myString) myString = Replace(myString,vbcrlf,"|~|") myString = Replace(Server.HTMLEncode(Trim(myString)),"|~|","<br />") CleanString = myString End Function %> That's the quickest one I could come up with, anyway - someone might be able to make that 1 line instead of three... :) P.S. the |~| is just some garbage combination I used that people most likely won't type in... you could use something else (unless I overlooked a way to do this easier, which is possible since I'm tired after auditioning for "Who wants to be a millionaire" at 7:00 this morning!). |
thanks yo
|
i did some research and this is finally what i came up with:
<% function cleanString(string_clean) string_clean = Trim(string_clean) string_clean = Server.HTMLEncode(string_clean) string_clean = Replace(string_clean, chr(13), "<br />") cleanString = string_clean End Function ' If you are using get function use: ' Response.Write(cleanString(Request.QueryString("message"))) Response.Write(cleanString(Request.Form("message"))) %> it works like a.. perfect script :thumbsup: Note: "message" is the name of the string i was getting form a form to process. You can see my progress at http://chronicyouth.com/news/?id=1 |
This is almost exactly what I need to do..
I'm trying to write a menu for a restaurant's website which has to be updatable from a database. I have only been taught asp.. I have made the connection to the database and I'm simply going to store the entire menu in one field.. that can be edited using one text box with all the information in. However... I'm using the following coding - <li>x</li><br> - Where x is the menu item. Therefore if I want 5 menu items I am going to repeat the above 5 times in the database field. This then presents a probelm when retrieving the data and displaying in a text box for editing. How would I format the database entry so that it reads - <li>x</li> <br> <li>x</li> <br> <li>x</li> <br> And not <li>x</li><br><li>x</li><br><li>x</li><br> ? I've tried using vbcrlf but I'm unsure of how to apply it correctly. Thanks for any help.. :) |
Got my head round it..
I just continued with the project and wrote the SQL update string.. I then applied this to the action property of the form and then entered the data as I wanted it to appear. I then executed the SQL update string I had wrote earlier and it then saved the information.. along with the formatting. Champion lol.. :thumbsup: |
| All times are GMT +1. The time now is 01:06 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.