Jump to content

[SOLVED] Convert html table to cvs format


zenag

Recommended Posts

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);
?>

Link to comment
Share on other sites

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"...??


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.