Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am working on a form completion view that needs to be easily copied. One of the inputs is a that displays multiple lines. So person can type out something that looks like this.
Dear Bob,
I am here to do this.
Thank you
SirRahal
I then take that data and store it into a database as varchar(1500) latin1_swedish_ci. The issue is that when I try to display this data in anything other than a it combines all the lines into 1. Example the not above would display like this:
Blockquote
Dear Bob, I am here to do this. Thank you SirRahal
The reason why I can't use a textarea to display it is because it doesn't copy and paste friendly.
Questions:
1) Is there another way of displaying this correctly?
2) Are there hidden characters in the string that I can use to identify in php and parse the text?
This code does work but I can't use a textarea:
<textarea>
<?php echo $model->description;?>
</textarea>
I believe you need to add nl2br when you output, e.g.
<?php echo nl2br($model->description);?>
Use CSS, and set white-space: pre on the container of the text.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to get all the visible text from a url. I need to clear all html code and get plain text.
The process does not have to be perfect, but I would like the text to be as clean as possible.
Do you know any way to make it relatively simple?
Thanks!
Javi.
Have a look at strip_tags function.
strip_tags — Strip HTML and PHP tags from a string
It may do the job.
You can get url the value of the query string using $_GET['the names in there']. and use strip_tags to get only the text.
function get_url(){ return $_GET['name userd'];}
and use something like this
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm developing a Blog, and I want to give some Style to the content of Every post body.
I'm storaging each post with a form into my data base, and then retrieving it into the blog.
My form has Title, Date and Body.
What I need is to retrieve the body, and separate the paragraphs, quotes, and whatever I want to.
My idea was to add characters in the body like % or & (% mean paragraph, and & quote for example), so the I can use explote function.
Is there a simpler way?
You'd honestly be so much better to store your post's content as HTML and simply output that.
You'll have to implement security yourself but this could be as simple as using the strip_tags() function - example:
$post_body = strip_tags($_POST['body'], '<p><strong><em><span><a><blockquote>');
This would simply strip all HTML tags other than <p>, <strong>, <em>, <span>, <a> and <blockquote>. That should prevent any issues with malicious users inserting Javascript code etc.
Hope that helps!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a form with a text field a user can edit, which will create a page on the website containing the text entered. How can I ensure the resulting page doesn't show anything malicious, no links, images or code, just raw text? Currently from php I'm using htmlspecialchars(), and when displaying the text on the page it's within xmp tags. Is that enough, or should I explicitly do things like validating against script tags etc?
edit: This question is different to the suggested question, because I'm not using sql.
edit 2: I accepted strip_tags. I'm now validating user input from php with htmlspecialchars(strip_tags("input")), and wrapping in xmp tags when displayed.
You can use strip_tags - it will remove everything in tags. http://php.net/manual/en/function.strip-tags.php
First of all: use prepared statments for your database storing, updating etc etc...
Second: You should escape the output using htmlspecialchars() function, It will just convert special characters to HTML entities, so if you put a script tag in there, It will not run.
Unless you want your users to post code just like here in StackOverflow, you can just use strip_tags() function as #user2182349 pointed out.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Right now I'm taking text from one form on a page to a separate page and form. I use $_GET to get the variable and just echo out the string between the textarea tags. The problem is formatting in the php seemed to be preserved. I got an if statement in there so it's pretty off.
I tried trimming the variable but that didn't do anything. Then I stripped out the PHP and typed free hand in between the tags. Is there a way to put text in a textarea without formatting?
Make sure your file ending is .php and that you properly open your PHP in the textarea, i.e.:
<textarea>
<?php if(isset($_GET['fieldName']) echo $_GET['fieldName']; ?>
</textarea>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am creating a forum software for my first time I know most of PHP just not a few things.
Anyway,
Say when someone hits enter like on this
"Like this i just hit enter"
It will display as a new line when the topic is posted how can I archive this?
Right now even if I went to a new line the post will still display like this "sssssssssssssssss" the user needs to add to break it but I need to disable HTML for security reasons.
I now I could get PHP to add automatically when the post is submitted but then will be displayed to the users and I be disabling html.
Thanks!
You need to use the nl2br() in the PHP. It automatically converts the linebreaks to <br> tags.
Say if the user typed data on the <textarea> of your form and when he clicks Submit , it reaches to your PHP page say submit.php , in that page you should be doing like this..
submit.php
<?php
$textareadata = isset($_POST['textareadata'])? nl2br(htmlspecialchars(($_POST['textareadata']))) : "Not Sent";