tags:

views:

60

answers:

2

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 :)

+1  A: 

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!

Frankie
Not just security problems. The code will likely have bugs and be hell to maintain
simendsjo
width*, not 'with'
Sam
@Sam Thanks! with would be a nice if/else feature to have in CSS, though! :)
Frankie
+1  A: 

Don't use regular expressions where is no need do to that. Use DOM to parse this.

Anpher