Jump to content

Recommended Posts

I'm using tinyMCE for textareas in a form.

 

Some users of the form are copy/pasting content from Word. I've managed to get fairly clean content using the Paste tinyMCE plugin.

 

However, in the case of tables, cell content is being pasted like this:

<td valign="top" width="148"><p>text</p></td>

 

How can I strip out those paragraph tags so that I simply get this:

<td valign="top" width="148">text</td>

 

Thanks in advance.

If you are certain it will always be a simple paragraph tag (no attributes) then you can use str_ireplace, as it is technically more efficient.

 

 

$content =str_ireplace(array('<p>','</p>'),'',$content);

 

If it may possibly have attributes, you can use preg_replace instead.

 

$content = preg_replace('~</?p[^>]*>~i','',$content);

If you are certain it will always be a simple paragraph tag (no attributes) then you can use str_ireplace, as it is technically more efficient.

 

 

$content =str_ireplace(array('<p>','</p>'),'',$content);

 

If it may possibly have attributes, you can use preg_replace instead.

 

$content = preg_replace('~</?p[^>]*>~i','',$content);

 

Very, very helpful. Thank you.

.. er... hang on... this solution won't work because I need to retain paragraph tags which are not within the table.

 

I want to strip out paragraph tags, but only those ones within td tags (which may or may not themselves contain attributes)...

 

...?

This RegExp should do it:

#(<td[^>]*>)(?:<p>(.*?)</p>)*(</td>)#

 

That said though, what you really should do is use DOMdocument or some other manner of properly traversing the DOM object. Regular Exp<b></b>ressions are for regular languages, not markup and other irregular languages.

Edited by Christian F.

Thank you very much.

 

... or some other manner of properly traversing the DOM object.

 

... and what would that be, exactly? Do you mean using javascript (which I know almost nothing about but which I'm keen to learn)?

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.