Replacing Strings
Moderator: General Moderators
Replacing Strings
I am building a little site and one of the things on it allows some people to give a description to certain items. Type in a text box, submit it, all is well. The only problem I am having is that when the user presses enter or puts in extra spaces and such, it doesn't show up because of the html and whitespace. So, is there some way I can replace all of the enters and extra spaces and such with html tags?
you could use preg_replace
something along the lines of:
something along the lines of:
Code: Select all
$string_entered = $_GET['myfieldname'];
if( somefunction_tocheck_textisnt_malicious($string_entered) )
{
// replace all whitespace with a single html space
preg_replace('/\s\s+/', ' ', $string_entered);
// replace all new lines with a BR tag
preg_replace('/\n/', '<BR>', $string_entered);
}
etc..- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
If you're looking to display all white space:
Code: Select all
<pre><? echo $myString; ?></pre>