Easy Regex

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    #1

    Easy Regex

    I've done alot of searching and can't seem to find this simple
    replacement for table tags.

    The end result is that I need to replace <td ABUNCHOFNONSENS Ewith
    <td>

    Here's what I have now:

    preg_replace('/^<td.+>/','<td>',$conte nt);

    It seems to do nothing, so I assume my pattern isn't matching anything.
  • Jeff

    #2
    Re: Easy Regex

    Chris wrote:
    I've done alot of searching and can't seem to find this simple
    replacement for table tags.
    >
    The end result is that I need to replace <td ABUNCHOFNONSENS Ewith
    <td>
    >
    Here's what I have now:
    >
    preg_replace('/^<td.+>/','<td>',$conte nt);
    Perhaps:

    $content = preg_replace('/^<td.+>/','<td>',$conte nt);

    and perhaps you don't want to match at the start of $content with "^"

    You may also wish to use the g and i switches.

    Jeff
    >
    It seems to do nothing, so I assume my pattern isn't matching anything.

    Comment

    • Paul Lautman

      #3
      Re: Easy Regex

      Chris wrote:
      I've done alot of searching and can't seem to find this simple
      replacement for table tags.
      >
      The end result is that I need to replace <td ABUNCHOFNONSENS Ewith
      <td>
      >
      Here's what I have now:
      >
      preg_replace('/^<td.+>/','<td>',$conte nt);
      >
      It seems to do nothing, so I assume my pattern isn't matching
      anything.
      Seems to work fine for me. I ran the following script:
      <?php
      $content = '<td ABUNCHOFNONSENS E>';
      echo htmlentities(pr eg_replace('/^<td.+>/','<td>',$conte nt));
      ?>

      and the output in my browser was <td>


      Comment

      • AnrDaemon

        #4
        Re: Easy Regex

        Greetings, Chris.
        In reply to Your message dated Wednesday, July 9, 2008, 23:11:44,
        I've done alot of searching and can't seem to find this simple
        replacement for table tags.
        The end result is that I need to replace <td ABUNCHOFNONSENS Ewith
        <td>
        Here's what I have now:
        preg_replace('/^<td.+>/','<td>',$conte nt);
        It seems to do nothing, so I assume my pattern isn't matching anything.
        There is no simple solution, but what you are trying is not correct one in any
        case.
        It will result in '<td>' on a string '<td>somestuff </td>'.
        I myself would try something like this:

        preg_replace('# <(list|of|tags) (?:\s+\w+\=(?:\ "[^\"]+\"|\'[^\']+\'|\S+))*\s*># i', '<$1>', $content);


        --
        Sincerely Yours, AnrDaemon <anrdaemon@free mail.ru>

        Comment

        Working...