SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    967
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Help with a regular expression

    The WYSIWYG editor in the CMS I'm using encloses tables in paragraphs. <p><table>
    This is causing a problem when it interfaces with another tool.

    I'm trying to remove the unwanted paragraph tags on the back side. It would need to be able to handle <p><table>, <p>[whitespace]<table>, <p> <table class='data'>, etc..

    This is what I've come up with so far.

    $find=array("[<p><table.*.>]","[</table></p>]");
    $replace=array("<table>","</table>","<table>","</table>");
    preg_replace($find,$replace,$str);

    Any help would be appreciated

    E

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    array("~<p>\s?<table~","~<table></p>~");
    array("<table","</table>");

    Try that

    Honestly though, it sounds like putting band-aids on a gunshot wound and you'll have other issues as well with that editor, should use something better.

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    PHP Code:
    $str preg_replace('~<p>\s*(<table(.*?)</table>)\s*</p>~i'"$1"$str); 
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •