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;






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



Link to post
Share on other sites

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



$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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...