Jump to content

Row changes in textare


XeroXer

Recommended Posts

Hi there...

This is my problem:
I am making a guestbook that uses a flat file.
Just a simple one for my mother-in-law's homepage.
The problem I am having is that when people enter a two rowed message the file bugs out.
Well they can enter a two-row message if they just type and type.
But as quickly as they press enter to change the row it doesn't work.
They can still post the message but in the textfile that just makes a new line and I would like it to change it to:[code]<br>[/code]

So what I would like to know is if I can get a normal 'enter' in a textarea to become a [code]<br>[/code] in the textfile?

Plz help... ;D
Link to comment
Share on other sites

Well thanks. That added the [code]<br>[/code] that I wanted.
Though it did not remove the line added.
The message still winds up in multiple rows in the textfile but now with [code]<br>[/code] after them.
So that helped in someway but I still need the linebreaker that comes with 'enter' removed...

[b]EDIT:[/b]
I also need it to add a [code]<br>[/code] like a automatic linebreaker.
If a person just types a loooooong message without any space the site expands.
Is it possible to make it do automatic linebreaker if no space is found?
Link to comment
Share on other sites

You'll want to use wordwarp:
[code]<?php

$text = "ttttttttttttttttttthhhhhhhhhhhhhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiiiiiiiiissssssssssssssssssssssss aaaaaaaaaaaaaaaaa lllllllllllllllllllllllllllllllllllllllllllloooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnngggggggggggggggggggggggggggggggg pppppppppppppppppppppppppppppppppppppppppppppppppppoooooooooooooooooooooooooooooooooooooooooooooooooooooooosssssssssssssssssssssssssssssssssssssssssssssssssssssstttttttttttttt.";

$newtext = wordwrap($text, 200, "<br />", true);

echo $newtext;
?>[/code]
Link to comment
Share on other sites

[size=12pt][u][color=red][b]NEW QUESTION![/b][/color][/u][/size]

Now I have another question still regarding my guestbook.
Thought I'd post it here instead of creating a new thread.

Now my flatfile guestbooks work almost as I want it.
I have gotten control over the length of the text entered.
I also got so it supports pressing 'enter' while writing a message.
Now I need it to remove the html code and anything similar. :-)

I want to strip the html code from the message before entering it into the textfile.
Or just print it out plain html and not working.
Because now people can enter what they like and ruin my guestbook.
A javascript that makes something annoying or a few rows of html that changes everything.

So please help me.
[b]1)[/b] How do i strip of the html code before entering it into the file?
[b]2)[/b] How do I print the file with the code intact but not working?
[b]3)[/b] Witch one of these do you think I should use?
Link to comment
Share on other sites

We have the php manual on the main site, phpfreaks.com

Here are links to those functions:
[url=http://www.phpfreaks.com/phpmanual/page/function.htmlentities.html]htmlentities[/url]
[url=http://www.phpfreaks.com/phpmanual/page/function.htmlspecialchars.html]htmlspecialchars[/url]
[url=http://www.phpfreaks.com/phpmanual/page/function.strip-tags.html]strip_tags[/url]
Link to comment
Share on other sites

If I use htmlentities and strip_tags on all fields will they still work?

Name, Email, Homepage and Message.
Those fields are in my guestbook.
If I use both those functions on all those fields will still long homepage and mail adresses work?
Link to comment
Share on other sites

Just one last thing... :-)
Is there any special order these should be taken in?
Or can I make somethings do more on one row?

This is my code for the message field right now:
[code]<?php
//Set message
$message = $_POST["message"];
$message = strip_tags($message);
$message = htmlentities($message, ENT_QUOTES);
$message = nl2br("$message");
$message = str_replace(array("\r", "\n"), '', $message);
$message = wordwrap($message, 50, "<br />", true);
?>[/code]

And for name, email and homepage it's this:
[code]<?php
//Set name
$name = $_POST["name"];
$name = strip_tags($name);
$name = htmlentities($name, ENT_QUOTES);
$name = wordwrap($name, 50, "<br />", true);
//Set email
$email = $_POST["email"];
$email = strip_tags($email);
$email = htmlentities($email, ENT_QUOTES);
$email = wordwrap($email, 50, "<br />", true);
//Set homepage
$homepage = $_POST["homepage"];
$homepage = strip_tags($homepage);
$homepage = htmlentities($homepage, ENT_QUOTES);
$homepage = wordwrap($homepage, 50, "<br />", true);
?>[/code]

Does that look good or not?


The message field is the only one that is a textarea. The other ones are just a "textrow".
That is why I don't use the nl2br and str_replace with name, email or homepage
Is that correct?
Link to comment
Share on other sites

Rather than doing each function seperatly, I'd do it all in one line.
[code]//Set name
$name = htmlentities(strip_tags($_POST['name']));[/code]
Also for each text field, I'd add the maxlength attribute to set the maxumin number of characters for each field. Then you dont need to use wordwrap.
Link to comment
Share on other sites

Thanks!
My rows now look like this:
[code]<?php
//Set name
$name = htmlentities(strip_tags($_POST['name']));
//Set email
$email = htmlentities(strip_tags($_POST['email']));
//Set homepage
$homepage = htmlentities(strip_tags($_POST['homepage']));
//Set message
$message = nl2br(htmlentities(strip_tags($_POST['message'])));
$message = str_replace(array("\r", "\n"), '', $message);
$message = wordwrap($message, 50, "<br />", true);
?>[/code]

That looks a lot better and I also added the lengthlimit on the textfields.
Thanks for all the help.

Will be back for more questions regarding other stuff :-)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.