Jump to content
Larry Ullman's Book Forums

Using Strip Tags, Html Entities And Special Characters While Showing Line Spacing


Recommended Posts

I've been reading the section of the book on how to use the following functions;

 

htmlspecialchars()

htmlentities()

strip_tags()

 

My question is, is it possible to use those functions to deal with HTML tags included in text entered into a form, but still maintain the line breaks in the form data.

 

For example if the following was entered into a textarea on a form;

 

This <strong>is</strong> a line

 

This is another line

 

How could the functions above be used so that when the data is printed to the browser it looks like this;

 

 

This is a line

 

This is another line

 

Thanks!

Link to comment
Share on other sites

strip_tags() takes a second parameter for allowable tags. So this code:

 


<?php

$string = "This <strong>is</strong> a line<br />This is another line";

echo strip_tags($string, '<br>');

/* Outputs:
* This is a line
* This is another line
*/
?>

 

Strips the <strong> tags and allows the <br />

 

Is that what you were after?

  • Upvote 1
Link to comment
Share on other sites

You can use that function also, you will see that there are often many different ways to achieve the same effect. As you read more of Larry's book(s) you'll see you can introduce applications that work similar to this form posting submission area with formatting options.

Link to comment
Share on other sites

 Share

×
×
  • Create New...