-1
I’m trying to incorporate some financial information from Infomoney into my application, and in the Investment Fund part it gives the ranking of the main portfolios. Only it returns the following string:
1º MCR-PRINCIPAL EQUITY INVESTMENT FUND +97,01%
I needed to blow this up string in 3 parts:
1st ranking of the portfolio second name of the wallet 3rd rate of return
I’m using this script:
if(!$fp=fopen("https://www.infomoney.com.br/mercados/fundos" , "r" ))
{
echo "Erro ao abrir a página de indices" ;
exit;
}
$conteudo = '';
while(!feof($fp))
{
$conteudo .= fgets($fp,1024);
}
fclose($fp);
$valorCompraHTML = explode('class="numbers">', $conteudo);
$ibovespa = trim(strip_tags($valorCompraHTML[$campo]));
$ibovespa = preg_replace(array("/\t/", "/\s{2,}/", "/\n/", "/\r/"), array("", " ", " ", " "), $ibovespa);
$ibovespa = explode(' ', $ibovespa);
$cart = trim($ibovespa[$explo]);
I have already found several articles about returning the first characters of a string. But how to return the last 8? I even found something on the Internet, but I couldn’t interpret it. The code was like this:
set @p = (SELECT LOCATE('+', '$xcart'));
SELECT SUBSTRING( 'xcart' , @p - 1 , @p + 5 );
The sql code is for database interaction. Are you using database interaction for anything? Or is your goal purely php, without sql?
– Jefferson Quesado
I’m not using any query no. It’s an Infomoney feature. I edited the question to display the code I’m using
– Webster Moitinho
I tried to use the code you gave me and I did so: $ptx = substr($iprima, -8); But it is returning the error :" Warning: substr() expects Parameter 1 to be string, array Given in D: xampp htdocs_responsivel views teste2.php on line 116".
– Webster Moitinho