zenag Posted June 25, 2008 Share Posted June 25, 2008 HI every body ...is there any way to convert html table to csv???if yes pls help me with codes..... Quote Link to comment https://forums.phpfreaks.com/topic/111792-solved-convert-html-table-to-cvs-format/ Share on other sites More sharing options...
zenag Posted June 25, 2008 Author Share Posted June 25, 2008 HI every body ...is there any way to convert html table to csv???if yes pls help me with codes..... Quote Link to comment https://forums.phpfreaks.com/topic/111792-solved-convert-html-table-to-cvs-format/#findComment-573930 Share on other sites More sharing options...
vbnullchar Posted June 25, 2008 Share Posted June 25, 2008 how do you generate the contents of your table? from database? Quote Link to comment https://forums.phpfreaks.com/topic/111792-solved-convert-html-table-to-cvs-format/#findComment-573996 Share on other sites More sharing options...
zenag Posted June 25, 2008 Author Share Posted June 25, 2008 no ...eg: <table><tr><td>name</td><td>age</td></tr> <tr><td>rajni</td></tr><tr><td>40</td></tr></table> like that... Quote Link to comment https://forums.phpfreaks.com/topic/111792-solved-convert-html-table-to-cvs-format/#findComment-573997 Share on other sites More sharing options...
vbnullchar Posted June 25, 2008 Share Posted June 25, 2008 is it generated dynamically? Quote Link to comment https://forums.phpfreaks.com/topic/111792-solved-convert-html-table-to-cvs-format/#findComment-573998 Share on other sites More sharing options...
zenag Posted June 25, 2008 Author Share Posted June 25, 2008 yeah... Quote Link to comment https://forums.phpfreaks.com/topic/111792-solved-convert-html-table-to-cvs-format/#findComment-573999 Share on other sites More sharing options...
sasa Posted June 25, 2008 Share Posted June 25, 2008 try <?php $a = 'blah bla <table><tr><td>name</td><td>age</td></tr> <tr><td>rajni</td><td>40</td></tr></table> mbrwgb '; preg_match('/<table(>| [^>]*>)(.*?)<\/table( |>)/is',$a,$b); $table = $b[2]; preg_match_all('/<tr(>| [^>]*>)(.*?)<\/tr( |>)/is',$table,$b); $rows = $b[2]; foreach ($rows as $row){ preg_match_all('/<td(>| [^>]*>)(.*?)<\/td( |>)/is',$row,$b); $out[] = strip_tags(implode(',',$b[2])); } $out = implode("\n", $out); print_r($out); ?> Quote Link to comment https://forums.phpfreaks.com/topic/111792-solved-convert-html-table-to-cvs-format/#findComment-574020 Share on other sites More sharing options...
zenag Posted June 25, 2008 Author Share Posted June 25, 2008 yeah ...thank u friend ...worked fine....but one more thing if i need to display contents outside table what i have to do..(eg)... $a = 'blah bla <table><tr><td>name</td><td>age</td></tr> <tr><td>rajni</td><td>40</td></tr></table> mbrwgb '; if i need to display "blah bla...mbrwgb"...?? Quote Link to comment https://forums.phpfreaks.com/topic/111792-solved-convert-html-table-to-cvs-format/#findComment-574031 Share on other sites More sharing options...
sasa Posted June 25, 2008 Share Posted June 25, 2008 $outside = preg_replace('/<table(>| [^>]*>)(.*?)<\/table(> |>)/is', '',$a); Quote Link to comment https://forums.phpfreaks.com/topic/111792-solved-convert-html-table-to-cvs-format/#findComment-574037 Share on other sites More sharing options...
zenag Posted June 25, 2008 Author Share Posted June 25, 2008 wow...fine thank u friend ...it works great........thanks a lot.. Quote Link to comment https://forums.phpfreaks.com/topic/111792-solved-convert-html-table-to-cvs-format/#findComment-574038 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.