how to dom parser html table which containing “<” symbol in php





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I want to make curl in php to get the data in html table on this website: https://bri.co.id/web/guest/deposit-interest-rate.
Here's the code I was trying:



<?php

error_reporting(E_ALL);
$url = "https://bri.co.id/web/guest/deposit-interest-rate";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);

$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->validateOnParse = true;
$dom->formatOutput = true;
libxml_use_internal_errors(true);

@$dom->loadHTML($html);

$table = $dom->getElementById('_Deposit_Rate_Display_Portlet_idrRate');

$row = $table->getElementsByTagName('tr')[1];
//var_dump($row);

$cols = $row->getElementsByTagName('td');
echo 'NOMINAL -> ' . $cols->item(0)->nodeValue. '<br />';
echo 'JANGKA WAKTU -> ' . $cols->item(1)->nodeValue.'<br />';
echo 'SUKU BUNGA COUNTER -> ' . $cols->item(2)->nodeValue;

?>


the result is:



NOMINAL ->
JANGKA WAKTU -> 1
SUKU BUNGA COUNTER -> 4.75%


I want the result is:



NOMINAL -> <100 Juta
JANGKA WAKTU -> 1
SUKU BUNGA COUNTER -> 4.75%


the problem is the data which contain "<" symbol not showing its show empty string.
How to dom parser "<" symbol so can show the output "<100 Juta" ?










share|improve this question























  • What does the HTML look like?

    – miken32
    Nov 25 '18 at 4:15











  • The issue is the <, which should be encoded as an HTMLEntity (&lt;). Because it is not encoded, the node isn't parsing correctly.

    – user2182349
    Nov 25 '18 at 5:30


















0















I want to make curl in php to get the data in html table on this website: https://bri.co.id/web/guest/deposit-interest-rate.
Here's the code I was trying:



<?php

error_reporting(E_ALL);
$url = "https://bri.co.id/web/guest/deposit-interest-rate";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);

$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->validateOnParse = true;
$dom->formatOutput = true;
libxml_use_internal_errors(true);

@$dom->loadHTML($html);

$table = $dom->getElementById('_Deposit_Rate_Display_Portlet_idrRate');

$row = $table->getElementsByTagName('tr')[1];
//var_dump($row);

$cols = $row->getElementsByTagName('td');
echo 'NOMINAL -> ' . $cols->item(0)->nodeValue. '<br />';
echo 'JANGKA WAKTU -> ' . $cols->item(1)->nodeValue.'<br />';
echo 'SUKU BUNGA COUNTER -> ' . $cols->item(2)->nodeValue;

?>


the result is:



NOMINAL ->
JANGKA WAKTU -> 1
SUKU BUNGA COUNTER -> 4.75%


I want the result is:



NOMINAL -> <100 Juta
JANGKA WAKTU -> 1
SUKU BUNGA COUNTER -> 4.75%


the problem is the data which contain "<" symbol not showing its show empty string.
How to dom parser "<" symbol so can show the output "<100 Juta" ?










share|improve this question























  • What does the HTML look like?

    – miken32
    Nov 25 '18 at 4:15











  • The issue is the <, which should be encoded as an HTMLEntity (&lt;). Because it is not encoded, the node isn't parsing correctly.

    – user2182349
    Nov 25 '18 at 5:30














0












0








0








I want to make curl in php to get the data in html table on this website: https://bri.co.id/web/guest/deposit-interest-rate.
Here's the code I was trying:



<?php

error_reporting(E_ALL);
$url = "https://bri.co.id/web/guest/deposit-interest-rate";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);

$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->validateOnParse = true;
$dom->formatOutput = true;
libxml_use_internal_errors(true);

@$dom->loadHTML($html);

$table = $dom->getElementById('_Deposit_Rate_Display_Portlet_idrRate');

$row = $table->getElementsByTagName('tr')[1];
//var_dump($row);

$cols = $row->getElementsByTagName('td');
echo 'NOMINAL -> ' . $cols->item(0)->nodeValue. '<br />';
echo 'JANGKA WAKTU -> ' . $cols->item(1)->nodeValue.'<br />';
echo 'SUKU BUNGA COUNTER -> ' . $cols->item(2)->nodeValue;

?>


the result is:



NOMINAL ->
JANGKA WAKTU -> 1
SUKU BUNGA COUNTER -> 4.75%


I want the result is:



NOMINAL -> <100 Juta
JANGKA WAKTU -> 1
SUKU BUNGA COUNTER -> 4.75%


the problem is the data which contain "<" symbol not showing its show empty string.
How to dom parser "<" symbol so can show the output "<100 Juta" ?










share|improve this question














I want to make curl in php to get the data in html table on this website: https://bri.co.id/web/guest/deposit-interest-rate.
Here's the code I was trying:



<?php

error_reporting(E_ALL);
$url = "https://bri.co.id/web/guest/deposit-interest-rate";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);

$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->validateOnParse = true;
$dom->formatOutput = true;
libxml_use_internal_errors(true);

@$dom->loadHTML($html);

$table = $dom->getElementById('_Deposit_Rate_Display_Portlet_idrRate');

$row = $table->getElementsByTagName('tr')[1];
//var_dump($row);

$cols = $row->getElementsByTagName('td');
echo 'NOMINAL -> ' . $cols->item(0)->nodeValue. '<br />';
echo 'JANGKA WAKTU -> ' . $cols->item(1)->nodeValue.'<br />';
echo 'SUKU BUNGA COUNTER -> ' . $cols->item(2)->nodeValue;

?>


the result is:



NOMINAL ->
JANGKA WAKTU -> 1
SUKU BUNGA COUNTER -> 4.75%


I want the result is:



NOMINAL -> <100 Juta
JANGKA WAKTU -> 1
SUKU BUNGA COUNTER -> 4.75%


the problem is the data which contain "<" symbol not showing its show empty string.
How to dom parser "<" symbol so can show the output "<100 Juta" ?







php curl dom html-table html-parsing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 3:40









codercoder

104




104













  • What does the HTML look like?

    – miken32
    Nov 25 '18 at 4:15











  • The issue is the <, which should be encoded as an HTMLEntity (&lt;). Because it is not encoded, the node isn't parsing correctly.

    – user2182349
    Nov 25 '18 at 5:30



















  • What does the HTML look like?

    – miken32
    Nov 25 '18 at 4:15











  • The issue is the <, which should be encoded as an HTMLEntity (&lt;). Because it is not encoded, the node isn't parsing correctly.

    – user2182349
    Nov 25 '18 at 5:30

















What does the HTML look like?

– miken32
Nov 25 '18 at 4:15





What does the HTML look like?

– miken32
Nov 25 '18 at 4:15













The issue is the <, which should be encoded as an HTMLEntity (&lt;). Because it is not encoded, the node isn't parsing correctly.

– user2182349
Nov 25 '18 at 5:30





The issue is the <, which should be encoded as an HTMLEntity (&lt;). Because it is not encoded, the node isn't parsing correctly.

– user2182349
Nov 25 '18 at 5:30












1 Answer
1






active

oldest

votes


















0














This will get the values - but it's not an ideal approach because if the HTML on the page changes, it will fail.



<?php

// Get the HTML
$url = "https://bri.co.id/web/guest/deposit-interest-rate";
$html = file_get_contents($url);

// Find the Rupiah header and discard everything before that
$rupiah = strpos($html,'<h2> Rupiah </h2>');
$chop = substr($html,$rupiah);

// Find he start and end of the Rupiah table
$tableStart = strpos($chop,'<table');
$tableEnd = strpos($chop,'</table>');

// Get the Rupiah table
$table = substr($chop,$tableStart,$tableEnd-$tableStart);

// Get the body of the Rupiah table
$tbodyStart = strpos($table,'<tbody>');
$tbody = substr($table,$tbodyStart+7);

// Get the rows
$rows = explode('<tr>',$tbody);

// Loop through all the rows and when you find the first blank one, get the cells
foreach ($rows as $r) {
if (trim($r) !== '') {
$cells = preg_split('#<td[^>]+>#',$r);
break;
}
}

// Loop through all the cells and echo out their contents (without any HTML tags)
foreach ($cells as $c) {
if (trim($c) !== '') {
echo strip_tags($c).PHP_EOL;
}
}





share|improve this answer
























  • then how to make it an ideal ?

    – coder
    Nov 25 '18 at 9:08











  • Find a different way to get the rates. Is there an API/RSS feed you could read? If this is a school project, the code is good enough. It does work. For every piece of code you write, you have to decide how much time you want to spend on it after you get it working. Als, things change, so today’s perfect code may not work tomorrow.

    – user2182349
    Nov 25 '18 at 12:11












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464455%2fhow-to-dom-parser-html-table-which-containing-symbol-in-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














This will get the values - but it's not an ideal approach because if the HTML on the page changes, it will fail.



<?php

// Get the HTML
$url = "https://bri.co.id/web/guest/deposit-interest-rate";
$html = file_get_contents($url);

// Find the Rupiah header and discard everything before that
$rupiah = strpos($html,'<h2> Rupiah </h2>');
$chop = substr($html,$rupiah);

// Find he start and end of the Rupiah table
$tableStart = strpos($chop,'<table');
$tableEnd = strpos($chop,'</table>');

// Get the Rupiah table
$table = substr($chop,$tableStart,$tableEnd-$tableStart);

// Get the body of the Rupiah table
$tbodyStart = strpos($table,'<tbody>');
$tbody = substr($table,$tbodyStart+7);

// Get the rows
$rows = explode('<tr>',$tbody);

// Loop through all the rows and when you find the first blank one, get the cells
foreach ($rows as $r) {
if (trim($r) !== '') {
$cells = preg_split('#<td[^>]+>#',$r);
break;
}
}

// Loop through all the cells and echo out their contents (without any HTML tags)
foreach ($cells as $c) {
if (trim($c) !== '') {
echo strip_tags($c).PHP_EOL;
}
}





share|improve this answer
























  • then how to make it an ideal ?

    – coder
    Nov 25 '18 at 9:08











  • Find a different way to get the rates. Is there an API/RSS feed you could read? If this is a school project, the code is good enough. It does work. For every piece of code you write, you have to decide how much time you want to spend on it after you get it working. Als, things change, so today’s perfect code may not work tomorrow.

    – user2182349
    Nov 25 '18 at 12:11
















0














This will get the values - but it's not an ideal approach because if the HTML on the page changes, it will fail.



<?php

// Get the HTML
$url = "https://bri.co.id/web/guest/deposit-interest-rate";
$html = file_get_contents($url);

// Find the Rupiah header and discard everything before that
$rupiah = strpos($html,'<h2> Rupiah </h2>');
$chop = substr($html,$rupiah);

// Find he start and end of the Rupiah table
$tableStart = strpos($chop,'<table');
$tableEnd = strpos($chop,'</table>');

// Get the Rupiah table
$table = substr($chop,$tableStart,$tableEnd-$tableStart);

// Get the body of the Rupiah table
$tbodyStart = strpos($table,'<tbody>');
$tbody = substr($table,$tbodyStart+7);

// Get the rows
$rows = explode('<tr>',$tbody);

// Loop through all the rows and when you find the first blank one, get the cells
foreach ($rows as $r) {
if (trim($r) !== '') {
$cells = preg_split('#<td[^>]+>#',$r);
break;
}
}

// Loop through all the cells and echo out their contents (without any HTML tags)
foreach ($cells as $c) {
if (trim($c) !== '') {
echo strip_tags($c).PHP_EOL;
}
}





share|improve this answer
























  • then how to make it an ideal ?

    – coder
    Nov 25 '18 at 9:08











  • Find a different way to get the rates. Is there an API/RSS feed you could read? If this is a school project, the code is good enough. It does work. For every piece of code you write, you have to decide how much time you want to spend on it after you get it working. Als, things change, so today’s perfect code may not work tomorrow.

    – user2182349
    Nov 25 '18 at 12:11














0












0








0







This will get the values - but it's not an ideal approach because if the HTML on the page changes, it will fail.



<?php

// Get the HTML
$url = "https://bri.co.id/web/guest/deposit-interest-rate";
$html = file_get_contents($url);

// Find the Rupiah header and discard everything before that
$rupiah = strpos($html,'<h2> Rupiah </h2>');
$chop = substr($html,$rupiah);

// Find he start and end of the Rupiah table
$tableStart = strpos($chop,'<table');
$tableEnd = strpos($chop,'</table>');

// Get the Rupiah table
$table = substr($chop,$tableStart,$tableEnd-$tableStart);

// Get the body of the Rupiah table
$tbodyStart = strpos($table,'<tbody>');
$tbody = substr($table,$tbodyStart+7);

// Get the rows
$rows = explode('<tr>',$tbody);

// Loop through all the rows and when you find the first blank one, get the cells
foreach ($rows as $r) {
if (trim($r) !== '') {
$cells = preg_split('#<td[^>]+>#',$r);
break;
}
}

// Loop through all the cells and echo out their contents (without any HTML tags)
foreach ($cells as $c) {
if (trim($c) !== '') {
echo strip_tags($c).PHP_EOL;
}
}





share|improve this answer













This will get the values - but it's not an ideal approach because if the HTML on the page changes, it will fail.



<?php

// Get the HTML
$url = "https://bri.co.id/web/guest/deposit-interest-rate";
$html = file_get_contents($url);

// Find the Rupiah header and discard everything before that
$rupiah = strpos($html,'<h2> Rupiah </h2>');
$chop = substr($html,$rupiah);

// Find he start and end of the Rupiah table
$tableStart = strpos($chop,'<table');
$tableEnd = strpos($chop,'</table>');

// Get the Rupiah table
$table = substr($chop,$tableStart,$tableEnd-$tableStart);

// Get the body of the Rupiah table
$tbodyStart = strpos($table,'<tbody>');
$tbody = substr($table,$tbodyStart+7);

// Get the rows
$rows = explode('<tr>',$tbody);

// Loop through all the rows and when you find the first blank one, get the cells
foreach ($rows as $r) {
if (trim($r) !== '') {
$cells = preg_split('#<td[^>]+>#',$r);
break;
}
}

// Loop through all the cells and echo out their contents (without any HTML tags)
foreach ($cells as $c) {
if (trim($c) !== '') {
echo strip_tags($c).PHP_EOL;
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 25 '18 at 5:31









user2182349user2182349

7,30821734




7,30821734













  • then how to make it an ideal ?

    – coder
    Nov 25 '18 at 9:08











  • Find a different way to get the rates. Is there an API/RSS feed you could read? If this is a school project, the code is good enough. It does work. For every piece of code you write, you have to decide how much time you want to spend on it after you get it working. Als, things change, so today’s perfect code may not work tomorrow.

    – user2182349
    Nov 25 '18 at 12:11



















  • then how to make it an ideal ?

    – coder
    Nov 25 '18 at 9:08











  • Find a different way to get the rates. Is there an API/RSS feed you could read? If this is a school project, the code is good enough. It does work. For every piece of code you write, you have to decide how much time you want to spend on it after you get it working. Als, things change, so today’s perfect code may not work tomorrow.

    – user2182349
    Nov 25 '18 at 12:11

















then how to make it an ideal ?

– coder
Nov 25 '18 at 9:08





then how to make it an ideal ?

– coder
Nov 25 '18 at 9:08













Find a different way to get the rates. Is there an API/RSS feed you could read? If this is a school project, the code is good enough. It does work. For every piece of code you write, you have to decide how much time you want to spend on it after you get it working. Als, things change, so today’s perfect code may not work tomorrow.

– user2182349
Nov 25 '18 at 12:11





Find a different way to get the rates. Is there an API/RSS feed you could read? If this is a school project, the code is good enough. It does work. For every piece of code you write, you have to decide how much time you want to spend on it after you get it working. Als, things change, so today’s perfect code may not work tomorrow.

– user2182349
Nov 25 '18 at 12:11




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464455%2fhow-to-dom-parser-html-table-which-containing-symbol-in-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()