I am opening an html file. Stripping out the html tags with the exception of <table> and <tr><td> tags. Then I want to do an ereg_replace however, I can not figure out a regular expression to change all table tags... Some of the tags have values like
<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=0 WIDTH=500> or
<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=6 WIDTH=700>..
and I guess the most efficient way to remove them is to use regular expressions. Can someone tell me what I am doing wrong here?
thanks.. here is the code.
<?
$string = fopen("dmo0130.html", "r");
$string2 = "";
while (!feof($string)) {
$temp = fgets($string,4096);
$string2 ="$string2$temp";
}
fclose ($string);
//echo $string2;
//$first = strpos($string2,"<TABLE");
//$string3 = substr ($string2 , $first , 6);
//$last = strpos($string2,">" , $first + 5);
//$string3 = substr ($string2 , $first , $last - $first +1);
//echo " $first $last \n";
//echo $string3;
//$string3 = ereg_replace("$string3", "<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=7 WIDTH=100%>", $string2);
//echo $string3;
$string3 = strip_tags($string2,"<table>,<tr><td></td></tr></i><b></b><p><br><h1></h1><i>");
//string4 = ereg_replace("/(<)(TABLE CELLSPACING=([0-9]) BORDER=([0-9]) CELLPADDING=([0-9]) WIDTH=([0-9]))(>)/", "<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=7 WIDTH=80%>", $string3);
string4 = ereg_replace("/(<)(TABLE)([a-zA-Z0-9])*(>)/", "<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=7 WIDTH=80%>", $string3);
//$string3 = ereg_replace("<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=0 WIDTH=500>", "<TABLE CELLSPACING=0 BORDER=0 CELLPADDING=7 WIDTH=100%>", $string3);
echo $string4,"\n";
//<TABLE\s/([a-zA-Z]\W[0-9])[*>)/
//}
?>