Jump to content

Finding table tags


Brandon Jaeger

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
Link to comment
https://forums.phpfreaks.com/topic/12916-finding-table-tags/
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]
Link to comment
https://forums.phpfreaks.com/topic/12916-finding-table-tags/#findComment-49592
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
Link to comment
https://forums.phpfreaks.com/topic/12916-finding-table-tags/#findComment-49975
Share on other sites

Archived

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

×
×
  • 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.