Jump to content

Archived

This topic is now archived and is closed to further replies.

Brandon Jaeger

Finding table tags

Recommended Posts

I need to tell if a string has [b]<table XXX>[/b] in it. XXX being stuff like [b]width[/b], [b]border[/b], etc. but it doesn't matter what those are. Also, "table" needs to be case-sensitive so users cannot exploit it.

Hopefully you know what I mean!

Thanks in advance.

Edit: I have this code and it doesn't seem to like to work with $_POST data:
[code]if(!preg_match("/<table[^>]*>.*<\/table>/" , $_POST["body"]))[/code]
Although if I do this it'll work fine:
[code]if(!preg_match("/<table[^>]*>.*<\/table>/" , "<table border=\"1\">something</table>"))[/code]

Also, here's the source for the form:
[code]<form method="post" action="usercp.php?edit.profile_layout">
<textarea name="body" rows="20" cols="65">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr valign="top">
<td width="35%" valign="top">
#TITLE_INFO#
<br \>
#CONTACT_INFO#
<br \>
#STATS#
<br \>
#BLOG#
</td>
<td width="65%" valign="top">
#PROFILE#
<br \>
#COMMENTS#
<br \>
#ADD_COMMENT#</td>
</tr>
</table>
</textarea>
<br \>        
<input type="submit" name="Submit" value="Update">
</form>[/code]

Any help?

---brandon

Share this post


Link to post
Share on other sites
Something like this:
[code]<?php

$str = '<table border="1" width="500" cellpadding="5" cellspacing="5">
  <tr>
    <td>Some data</td>
  </tr>
</table>

bal';

if(preg_match("#<table ([^>]*)>(.*?)</table>#is", $str, $matches))
{
    #echo '<pre>' . htmlentities(print_r($matches, true)) . '</pre>';

    // get our table attributes
    $attr = explode(" ", $matches[1]);

    // echo out our attributes
    echo '<pre>' . htmlentities(print_r($attr, true)) . '</pre>';
}

?>[/code]

Share this post


Link to post
Share on other sites
Thank you!

Do you know why that other pattern didn't work with $_POST data (but did with a regular string)?

Share this post


Link to post
Share on other sites
Actually,

How would I tell if there are <table></table> tags at the [b]beginning/end[/b] of a string?

Valid string:
[code]$str = "<table>content</table>";[/code]
Invalid strings:
[code]$str = "something<table>content</table>something";
$str = "<table>content</table>something";[/code]

Thanks in advance.

---brandon

Share this post


Link to post
Share on other sites

×

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.