Possible to strip out an empty <p></p>?

Hey guys,

We built a custom CMS at my work, the site currently using it is working great.

One final issue that we’re working to resolve is that when someone pastes in content for one of their pages, the WYSIWYG adds an empty

tag at the end of the content. (I believe this is due to empty white space being pasted in from Microsoft Word or a similar program).

What this causes is the side navigation will get dumped under the main content. (So the right column gets put under the left column).

It’s strange, but once the empty

is removed, the problem is fixed and the columns return to their proper place.

Is there a function available to just strip out this empty tag if it exists without harming any of the other tags?
It ONLY gets added as the last thing, so maybe I can strip out the final 7 characters somehow? (

= 7 characters).

However a problem I see with this is it only happens sometimes, thus I can’t go stripping out the last 7 characters if the problem doesn’t exist, or their content will get stripped.

We store the content into the database with a simple:

$content = $_POST[‘content’];

I’ve had similar problems where I had to replace all white space in a string with dashes, but having trouble applying that function to this…

Any help would be great! Thanks.

well, if you don’t want to allow html at all, you could use strip_tags() to completely remove it, or use str_replace() to replace the tags with something else. If you’re storing the html in a table, then use htmlentities() to encode the tags (use html_entity_decode() to reverse it).

And i just remembered where i used that str_replace. In my support script, i have a basic template system that uses strings to represent different things (%user% would be the username, etc), but before i put that into the table, i replace the variables with the real info.
[php]//for default answer
$uname = $_POST[‘u_name’];
$aname = $_POST[‘a_name’];

//replace template variables
$find = array(’%name%’, ‘%admin%’, ‘\n’);
$repl = array($uname, $aname, “
”);

$ansr = str_replace($find, $repl, $_POST[‘n_answer’]);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service