I am attempting to come up with a regular expression to remove a specific table row, or table column and replace it with something else. I am using preg_replace and an array of regular expressions.

Here is a sample of the code that needs to be changed:

<table width="100%" border="0" cellpadding="3" cellspacing="1" border="0" class="forumline" bgcolor=""#ffffff">
<tr>
<td class="row2" align="center"><div class="maintitle">{L_CONFIGURATION_TITLE}</div></td>
</tr><tr>
<td class="row2"><div class="genmed">{L_CONFIGURATION_EXPLAIN}</div></td>
</tr></table>
<form action="{S_CONFIG_ACTION}" method="post">
<table width="99%" cellpadding="3" cellspacing="1" border="0" align="center" class="forumline">
<tr> 
<th colspan="2">{L_GENERAL_SETTINGS}</th>
</tr>
<tr> 
<td class="row1" width="38%">{L_SERVER_NAME}</td>
<td class="row2" width="62%"> 
<input type="text" maxlength="255" size="40" name="server_name" value="{SERVER_NAME}" class="post" />
</td>
</tr>
<tr> 
<td class="row1">{L_SERVER_PORT}<br />
<span class="gensmall">{L_SERVER_PORT_EXPLAIN}</span></td>
<td class="row2"> 
<input type="text" maxlength="5" size="5" name="server_port" value="{SERVER_PORT}" class="post" />
</td>
</tr>

Now what I want to do is to remove a table row that contains {SERVER_NAME}, just that row, or maybe JUST that column. This is what I have so far but it grabs the very first table row and deletes everything up to the ending /tr> after SERVER_NAME.

'<tr[^>]*?>.*?SERVER_NAME.*?</tr>'si

any help would be appreciated.

carl

    If there is already a post here that could help me answer this question, please help me out. I performed a search but could not find anything relevant.

    Thanks

      read what people think about bumping while waiting for someone to answer:
      http://www.phpbuilder.com/board/showthread.php?s=&threadid=10220471
      😉

      the problem is that matching always starts at the leftmost position in the string and is continued until the last requirement of the pattern is fulfilled.
      The beginning of the match would only be moved to the next character if matching fails at the current position, no matter whether you use the ungreedy mode or not.

      so you'd need to be more specific, could work like this
      '<tr[>]>[<](<(?!tr)[<])SERVER_NAME.*?</tr>'si
      this does a negative lookahead for 'tr' whenever an opening angular bracket is encountered.

        Some sites do not care about bumping, but I am caught in the assumption vortex :-) Sorry. It will not happen again.

        My anxiety got the best of me, when you need help you want it now, what's the world coming too. :-)

        Thanks for the reply, I will give that a try. I have only been working with PHP for about 4 months now. And my learning curve turns into a right angle (to the bad) when it comes to regular expressions. I have read countless articles (some I found usefully) and algebra equations (regular expressions can seem like them) are not my forte.

        Thanks again.

        Carls

          Write a Reply...