I am trying to incorporate some of Infomoney's financial information into my application, and in the Investment Fund part it gives the ranking of the top portfolios. But it returns the following string :
1st MCR-MAIN INVESTMENT FUND IN SHARES +97.01%
I needed to explode this string in 3 parts:
1st ranking of the portfolio 2nd name of the wallet 3rd profitability index
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 few characters of a string. But how to return the last 8? I even found something on the internet, but I could not interpret it. The code looks like this:
set @p = (SELECT LOCATE('+', '$xcart'));
SELECT SUBSTRING( 'xcart' , @p - 1 , @p + 5 );