0

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

3
  • 1
    ereg functions are deprecated. Commented Jun 17, 2010 at 9:35
  • And mixing ereg and preg functions together is even more ew. Commented Jun 17, 2010 at 9:36
  • 1
    And using Regexes to parse HTML is even more ewww. :) Commented Jun 17, 2010 at 9:36

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.