{"id":165,"date":"2020-10-12T01:20:03","date_gmt":"2020-10-12T01:20:03","guid":{"rendered":"https:\/\/barahasoft.com.np\/blog\/?post_type=codings&#038;p=165"},"modified":"2020-10-13T01:49:07","modified_gmt":"2020-10-13T01:49:07","slug":"how-to-fetch-gold-sliver-price-in-nepal","status":"publish","type":"codings","link":"https:\/\/barahasoft.com.np\/blog\/codings\/how-to-fetch-gold-sliver-price-in-nepal\/","title":{"rendered":"How to fetch gold\/sliver price in Nepal"},"content":{"rendered":"\n<p>In this post I will go through PHP code to fetch gold\/silver price data from any site content without any API. Here I am using PHP core functions to get content from site and manipulate string content to get required value because content may contains unnecessary html strings.<\/p>\n\n\n\n<p>Gold\/Silver price always changes and it&#8217;s been part of daily uses data. If you want to show current price of gold\/silver in your website or app , you can use this code.<\/p>\n\n\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$url = 'https:\/\/www.hamropatro.com\/gold\/';\n$content = file_get_contents($url);\n$d1 = explode('&lt;ul class=&quot;gold-silver&quot; style=&quot;margin: 0&quot;&gt;', $content);\n$d2 = explode(&quot;&lt;\/ul&gt;&quot;, $d1[1]);\n$d3 = $d2[0];\n$d4 = explode('&lt;li', $d3);\n$arrName = array();\n$arrPrice = array();\n$pushName = true;\nforeach ($d4 as $key =&gt; $value) {\n    if ($key == 0) {\n        continue;\n    }\n    $final = $this-&gt;getStringBetween($value, &quot;&gt;&quot;, &quot;&lt;&quot;);\n    if ($pushName) {\n        array_push($arrName, $final);\n        $pushName = false;\n    } else {\n        array_push($arrPrice, trim($final));\n        $pushName = true;\n    }\n}\n$finalArray = array();\nforeach ($arrName as $key =&gt; $value) {\n    $tempArray[&quot;name&quot;] = $value;\n    $tempArray[&quot;price&quot;] = $arrPrice[$key];\n    array_push($finalArray, $tempArray);\n}\n$finalJson = json_encode($finalArray);\necho $finalJson;\n\nfunction getStringBetween($str, $start, $end) {\n    $subtring_start = strpos($str, $start);\n    $subtring_start += strlen($start);\n    $size = strpos($str, $end, $subtring_start) - $subtring_start;\n    return substr($str, $subtring_start, $size);\n}\n<\/pre>\n\n\n<p>  <strong>NB:<\/strong> it may give error if any changes in the content of site. <\/p>\n","protected":false},"featured_media":0,"parent":0,"template":"","tags":[41,42,43,44],"language":[37],"ctype":[40],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to fetch gold\/sliver price in Nepal - BS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/barahasoft.com.np\/blog\/codings\/how-to-fetch-gold-sliver-price-in-nepal\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to fetch gold\/sliver price in Nepal - BS Blog\" \/>\n<meta property=\"og:description\" content=\"In this post I will go through PHP code to fetch gold\/silver price data from any site content without any API. Here I am using PHP core functions to get content from site and manipulate string content to get required value because content may contains unnecessary html strings. Gold\/Silver price always changes and it&#8217;s been [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/barahasoft.com.np\/blog\/codings\/how-to-fetch-gold-sliver-price-in-nepal\/\" \/>\n<meta property=\"og:site_name\" content=\"BS Blog\" \/>\n<meta property=\"article:modified_time\" content=\"2020-10-13T01:49:07+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#website\",\"url\":\"https:\/\/barahasoft.com.np\/blog\/\",\"name\":\"BS Blog\",\"description\":\"Baraha Soft Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/barahasoft.com.np\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/codings\/how-to-fetch-gold-sliver-price-in-nepal\/#webpage\",\"url\":\"https:\/\/barahasoft.com.np\/blog\/codings\/how-to-fetch-gold-sliver-price-in-nepal\/\",\"name\":\"How to fetch gold\/sliver price in Nepal - BS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#website\"},\"datePublished\":\"2020-10-12T01:20:03+00:00\",\"dateModified\":\"2020-10-13T01:49:07+00:00\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/barahasoft.com.np\/blog\/codings\/how-to-fetch-gold-sliver-price-in-nepal\/\"]}]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/codings\/165"}],"collection":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/codings"}],"about":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/types\/codings"}],"wp:attachment":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/media?parent=165"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/tags?post=165"},{"taxonomy":"language","embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/language?post=165"},{"taxonomy":"ctype","embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/ctype?post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}