PHP How to print text AND html tags from DOMDocument, nodeValue instead only text? -
i writing following code .html file. read out values working. text can see @ "output". need print html tags inside <td>
tags too!
here browser prints out:
hoehere spruenge 2x 2x 2x 2x adrenalin-modus (zeitlupe, staerkere schlaege) (**) 2x maximaler sex-appeal 2x 3x
and wont get:
hoehere spruenge 2x <img src="images/cheats/psx/o.gif"> 2x <img src="images/cheats/psx/d.gif"> 2x <img src="images/cheats/psx/o.gif"> <img src="images/cheats/psx/l.gif"> <img src="images/cheats/psx/r.gif"> <img src="images/cheats/psx/ve.gif"> 2x <img src="images/cheats/psx/r2.gif">
and on...
code inside data.html file:
<table border cellpadding="2"> <tr> <td>höhere sprünge</td> <td>2x <img src="images/cheats/psx/o.gif"> 2x <img src="images/cheats/psx/d.gif"> 2x <img src="images/cheats/psx/o.gif"> <img src="images/cheats/psx/l.gif"> <img src="images/cheats/psx/r.gif"> <img src="images/cheats/psx/ve.gif"> 2x <img src="images/cheats/psx/r2.gif"></td> </tr> <tr> <td>adrenalin-modus (zeitlupe, stärkere schläge) (**)</td> <td>2x <img src="images/cheats/psx/k.gif"> <img src="images/cheats/psx/ve.gif"> <img src="images/cheats/psx/r1.gif"> <img src="images/cheats/psx/l1.gif"> <img src="images/cheats/psx/k.gif"> <img src="images/cheats/psx/u.gif"> <img src="images/cheats/psx/l.gif"> <img src="images/cheats/psx/k.gif"></td> </tr> <tr> <td>maximaler sex-appeal</td> <td><img src="images/cheats/psx/ks.gif"> 2x <img src="images/cheats/psx/d.gif"> <img src="images/cheats/psx/o.gif"> <img src="images/cheats/psx/ks.gif"> <img src="images/cheats/psx/r1.gif"> <img src="images/cheats/psx/l2.gif"> <img src="images/cheats/psx/o.gif"> <img src="images/cheats/psx/d.gif"> 3x <img src="images/cheats/psx/l1.gif"></td> </tr> <tr> </table>
php code:
<?php // array json response $response = array(); include("functions.php"); // check required fields if (isset($_post['cheat_value'])) { $htmltext = $_post['cheat_value']; $gameid = $_post['game_id']; $howto = $_post['cheat_howto']; $plattform = $_post['plattform_id']; $myfile = "data.html"; $fh = fopen($myfile, 'w') or die("can't open file"); $stringdata = $htmltext; fwrite($fh, $stringdata); fclose($fh); require_once 'db_connect.php'; // connecting db $db = new db_connect(); // new dom object $dom = new domdocument(); //load html $html = $dom->loadhtmlfile("data.html"); //discard white space $dom->preservewhitespace = false; //the table tag name $tables = $dom->getelementsbytagname('table'); //get rows table $rows = $tables->item(0)->getelementsbytagname('tr'); // loop on table rows foreach ($rows $row) { // each column tag name $cols = $row->getelementsbytagname('td'); // echo values if($cols->item(1)->nodevalue && $cols->item(0)->nodevalue){ $datetime = date("y-m-d"); // mysql inserting new row $col1 = $cols->item(0)->nodevalue; $col2 = $cols->item(1)->nodevalue; $col1 = ereg_replace ("ä", "ae", $col1); $col1 = ereg_replace ("ö", "oe", $col1); $col1 = ereg_replace ("ü", "ue", $col1); $col1 = ereg_replace ("ß", "ss", $col1); $col1 = ereg_replace ("Ä", "ae", $col1); $col1 = ereg_replace ("Ö", "oe", $col1); $col1 = ereg_replace ("Ü", "ue", $col1); $col2 = ereg_replace ("ä", "ae", $col2); $col2 = ereg_replace ("ö", "oe", $col2); $col2 = ereg_replace ("ü", "ue", $col2); $col2 = ereg_replace ("ß", "ss", $col2); $col2 = ereg_replace ("Ä", "ae", $col2); $col2 = ereg_replace ("Ö", "oe", $col2); $col2 = ereg_replace ("Ü", "ue", $col2); echo $col1; echo "<br>"; echo $col2; }else{ } } } ?>
the following graps html inside <td>
:
$str = ' <table border cellpadding="2"> <tr> <td>höhere sprünge</td> <td>2x <img src="images/cheats/psx/o.gif"> 2x <img src="images/cheats/psx/d.gif"> 2x <img src="images/cheats/psx/o.gif"> <img src="images/cheats/psx/l.gif"> <img src="images/cheats/psx/r.gif"> <img src="images/cheats/psx/ve.gif"> 2x <img src="images/cheats/psx/r2.gif"></td> </tr> <tr> <td>adrenalin-modus (zeitlupe, stärkere schläge) (**)</td> <td>2x <img src="images/cheats/psx/k.gif"> <img src="images/cheats/psx/ve.gif"> <img src="images/cheats/psx/r1.gif"> <img src="images/cheats/psx/l1.gif"> <img src="images/cheats/psx/k.gif"> <img src="images/cheats/psx/u.gif"> <img src="images/cheats/psx/l.gif"> <img src="images/cheats/psx/k.gif"></td> </tr> <tr> <td>maximaler sex-appeal</td> <td><img src="images/cheats/psx/ks.gif"> 2x <img src="images/cheats/psx/d.gif"> <img src="images/cheats/psx/o.gif"> <img src="images/cheats/psx/ks.gif"> <img src="images/cheats/psx/r1.gif"> <img src="images/cheats/psx/l2.gif"> <img src="images/cheats/psx/o.gif"> <img src="images/cheats/psx/d.gif"> 3x <img src="images/cheats/psx/l1.gif"></td> </tr> <tr> </table> '; $doc = new domdocument(); $doc->loadhtml($str); $tds = $doc->getelementsbytagname('td'); $doc->loadhtml($str); //header("content-type: text/plain"); $len = $tds->length; for($i = 1; $i < $len; $i += 2){ echo $doc->savexml($tds->item($i)) . "\n"; }
note in loop $i
steps 2
skip headers. should change headers <th>
elements
Comments
Post a Comment