Take data from a JS and display with PHP

Asked

Viewed 39 times

-1

I’m trying to get some data from an array that contains within a JS that is available at this link.

http://www.lotterytaiwan.com/intl/BR/results.js

I’m using php

 <?php
        $texto = file_get_contents('http://www.lotterytaiwan.com/intl/BR/results.js');
        
        $ini = strpos($texto, "var draw_BRMS=new Array(");
        $fim = strpos($texto, ');');
        $url = substr($texto, $ini+12, ($fim-$ini)-12);
    
    
    ?>
    <?php echo $url;?>

But the result is something like:

S=new Array("11","16","20","24","39","53"); var bonu_BRMS=new Array("6","0",""); var jdat_BRMS=new Array(3,2017,11,1); var jamt_BRMS="2,500,000"; var jchg_BRMS="17,500,000"; var jimg_BRMS="down.gif"; var game_BRDS1="Dupla Sena 1"; var date_BRDS1=new Array(6,2021,6,12); var next_BRDS1=new Array(2,2021,6,15); var draw_BRDS1=new Array("01","09","24","35","36","38"); var bonu_BRDS1=new Array("6","0",""); var jdat_BRDS1=new Array(2,2011,2,22); var jamt_BRDS1="600,000"; var jchg_BRDS1="200,000"; var jimg_BRDS1="down.gif"; var game_BRDS2="Dupla Sena 2"; var date_BRDS2=new Array(6,2021,6,12); var next_BRDS2=new Array(2,2021,6,15); var draw_BRDS2=new Array("07","12","16","19","32","48"); var bonu_BRDS2=new Array("6","0",""); var jdat_BRDS2=new Array(0,0,0,0); var jamt_BRDS2="0"; var jchg_BRDS2="0"; var jimg_BRDS2=""; var game_BRQU="Quina"; var date_BRQU=new Array(1,2021,6,14); var next_BRQU=new Array(2,2021,6,15); var draw_BRQU=new Array("10","19","28","29","73"); var bonu_BRQU=new Array("5","0",""); var jdat_BRQU=new Array(2,2017,10,31); var jamt_BRQU="4,500,000"; var jchg_BRQU="900,000"; var jimg_BRQU="up.gif"; var game_BRLM="LotoMania"; var date_BRLM=new Array(5,2021,6,11); var next_BRLM=new Array(2,2021,6,15); var draw_BRLM=new Array("07","08","09","13","17","23","26","37","39","40","42","43","45","53","55","58","72","77","82","87"); var bonu_BRLM=new Array("20","0",""); var jdat_BRLM=new Array(2,2017,10,31); var jamt_BRLM="2,000,000"; var jchg_BRLM="800,000"; var jimg_BRLM="up.gif"; var game_BRLF="LotoFacil"; var date_BRLF=new Array(1,2021,6,14); var next_BRLF=new Array(2,2021,6,15); var draw_BRLF=new Array("01","03","06","07","08","11","14","15","17","19","20","21","22","24","25"); var bonu_BRLF=new Array("15","0",""); var jdat_BRLF=new Array(3,2017,11,1); var jamt_BRLF="5,100,000"; var jchg_BRLF="3,400,000"; var jimg_BRLF="up.gif"; var game_BRTM="TimeMania"; var date_BRTM=new Array(6,2021,6,12); var next_BRTM=new Array(2,2021,6,15); var draw_BRTM=new Array("11","17","19","21","37","66","69"); var bonu_BRTM=new Array("7","0",""); var jdat_BRTM=new Array(2,2014,12,30); var jamt_BRTM="650,000"; var jchg_BRTM="11,350,000"; var jimg_BRTM="down.gif"; var game_BRTS1="Tele Sena 1"; var date_BRTS1=new Array(0,2021,5,2); var next_BRTS1=new Array(0,2021,5,9); var draw_BRTS1=new Array("05","08","10","38","44"); var bonu_BRTS1=new Array("5","0",""); var game_BRTS2="Tele Sena 2"; var date_BRTS2=new Array(0,2021,5,9); var next_BRTS2=new Array(0,2021,5,16); var draw_BRTS2=new Array("06","11","14","23","25"); var bonu_BRTS2=new Array("5","0",""); var game_BRTS3="Tele Sena 3"; var date_BRTS3=new Array(0,2021,5,16); var next_BRTS3=new Array(0,2021,5,23); var draw_BRTS3=new Array("02","18","29","35","40"); var bonu_BRTS3=new Array("5","0",""); var game_BRTS4="Tele Sena 4"; var date_BRTS4=new Array(0,2021,5,23); var next_BRTS4=new Array(0,2021,5,30); var draw_BRTS4=new Array("12","16","22","36","48"); var bonu_BRTS4=new Array("5","0",""); var game_BRTS5="Tele Sena 5"; var date_BRTS5=new Array(0,2021,5,30); var next_BRTS5=new Array(0,2021,6,6); var draw_BRTS5=new Array("15","17","28","34","41"); var bonu_BRTS5=new Array("5","0",""); var game_BRTS6="Tele Sena 6"; var date_BRTS6=new Array(0,2021,6,6); var next_BRTS6=new Array(0,2021,6,13); var draw_BRTS6=new Array("19","20","27","33","47"); var bonu_BRTS6=new Array("5","0",""); var game_BRTSALL="Tele Sena All Numbers"; var date_BRTSALL=new Array(0,2021,6,6); var next_BRTSALL=new Array(0,2021,6,13); var draw_BRTSALL=new Array("50 51 52 53 55 57 58 59 62 64 65 67 69 71 72 73 74 76 77 78 81

I need to take the data separately as for example: var draw_BRMS=new Array and show only 11 16 20 24 39 53

1 answer

-1


Hello! See if this code works:

        $texto = file_get_contents('http://www.lotterytaiwan.com/intl/BR/results.js');
        
        $filtro = strchr($texto, 'var draw_BRMS=new Array('); //procura a string
        $item = strchr($filtro,')', true); // corta a parte interessada
        $numeros = strchr($item, '"'); // deixa somente os numeros

        $numeros_sem_aspas = str_replace('"','',$numeros); // formata string...
        $numeros_sem_virgula = str_replace(',',' ',$numeros_sem_aspas);

        echo $numeros_sem_virgula; //saida: 11 16 20 24 39 53 

reference: https://www.w3schools.com/php/func_string_strchr.asp

  • Simply, perfect! Just an observation that already leaves a little of the scope of doubt. There is some way to generate a variable for each number, for example: 11 $numeros_sem_virgula_um, 16 $numeros_sem_virgula_two ...

  • For this use the function explode ex: $array_de_numeros[] = explode(' ', $numeros_sem_virgula);. Each input of the array will be a number: echo $array_de_numeros[0]; // 11

Browser other questions tagged

You are not signed in. Login or sign up in order to post.