Reputation: 1
hello all in my site users can insert data using tabular format. that table can be of any style. but im using regex to give those tables a standard format of our site.but when im using regex it works well but it is removing colspan. but i need colspan widout it tables looks very odd. will anyone please tell me wats wrong with my regex?? following is my regex codes:
$table=eregi_replace("<table[^>]*>","<table width='100%' border='0' cellspacing='0' cellpadding='0' class='tabularData'>", $table);
$table= preg_replace('/style\s*=\s*(\'|").+(\'|")/i', '', $table);
$table= preg_replace('/bgcolor\s*=\s*(\'|").+(\'|")/i', '', $table);
$table=eregi_replace("<span[^>]*>","",$table);
thanks in advance :)
Upvotes: 0
Views: 79
Reputation: 4617
Don't use regular expressions where is no need do to that. Use DOM to parse this.
Upvotes: 1
Reputation: 25165
You can easily style the tables with Javascript. In fact you should. Having a regex run like that over users code can lead to security problems if the user figures out your regex (and if you fail to implement it properly; which will probably be the case).
// jquery table styling example (picks up all tables)
$('table').css({
'width': '100%',
'background-color': '#F00'
});
Hope it helps!
Upvotes: 1