Jump to content


Photo

Finding table tags


  • Please log in to reply
3 replies to this topic

#1 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 26 June 2006 - 08:55 AM

I need to tell if a string has <table XXX> in it. XXX being stuff like width, border, 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:
if(!preg_match("/<table[^>]*>.*<\/table>/" , $_POST["body"]))
Although if I do this it'll work fine:
if(!preg_match("/<table[^>]*>.*<\/table>/" , "<table border=\"1\">something</table>"))

Also, here's the source for the form:
<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>

Any help?

---brandon
PHP is my friend (=

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 June 2006 - 09:46 AM

Something like this:
<?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>';
}

?>


#3 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 26 June 2006 - 09:57 AM

Thank you!

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

#4 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 27 June 2006 - 06:41 AM

Actually,

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

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

Thanks in advance.

---brandon
PHP is my friend (=




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users