1
I have the following problem, in the program below, I took the forms of a site, but I have to specify the exact length of the line that has the form(96), I would have the possibility to take this number without having to specify manually.
<?php
$url = file_get_contents('site.com');
if(!$url) {
trigger_error('Não foi possível ler a url', E_USER_NOTICE);
}
$var1 = explode("<form", $url);
$string = array();
// Pega o formulário do arquivo HTML.
for($i = 0; $i < 96; $i++) {
$string[0][$i] = $var1[1][$i];
}
?>
I tried to use the foreach, but it doesn’t return the right number.
$i = 0;
foreach($var1 as $valor => $detalhes) {
foreach($detalhes as $detalhes => $saida) {
$i++;
}
}
Grateful!
I didn’t understand that 96... would be what?
– Sam
It is the line size of the html form, e.g.: <form method="post" class="form" action=...>.
– Lucas Oliveira
In total 96 characters
– Lucas Oliveira
Try it this way
strlen($var1[1])
– Sam
The size of the array is
count( )
, and string size hasstrlen( )
andmb_strlen( )
– Bacco
Opa, the strlen function worked! in case it takes up to the last line of the html file, but I solve with an if. Fight!
– Lucas Oliveira
Get used to a read on PHP manual, good part has the option of Portuguese. If you give a general view, you will get a good idea. I’m not just talking about researching the function you need, I’m talking about a general view to know where to find what you need.
– Bacco
Yes, it really helps a lot. I’ll take it as a total reference. Thank you very much!
– Lucas Oliveira