Brandon Jaeger Posted June 26, 2006 Share Posted June 26, 2006 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 26, 2006 Share Posted June 26, 2006 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] Quote Link to comment Share on other sites More sharing options...
Brandon Jaeger Posted June 26, 2006 Author Share Posted June 26, 2006 Thank you!Do you know why that other pattern didn't work with $_POST data (but did with a regular string)? Quote Link to comment Share on other sites More sharing options...
Brandon Jaeger Posted June 27, 2006 Author Share Posted June 27, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.