[英]How do I convert plaintext to a String in php?
What I want to do is get the number of pages for the html file, I already got the section that I want but I can't gat the numbers alone. 我想做的是获取html文件的页数,我已经获取了我想要的部分,但是我不能单独列出数字。
<?php
include_once 'simple_html_dom.php';
error_reporting(E_ERROR);
$html = file_get_html('http://www.seccionamarilla.com.mx/resultados/hospitales/distrito-federal/1');
foreach($html->find('.paginas',0) as $e){
//echo $e->plaintext;
$res = $e->plaintext;
$text = (string)$res;
echo $res."<br>";
echo $text."<br>";
echo substr($text, 10);
}
?>
I am using the yellowpages as an example. 我以黄页为例。 This are the results i'm getting.
这就是我得到的结果。
Resultados (3892) Página 1 - 2 - 3 - 4 - 5
Resultados (3892) Página 1 - 2 - 3 - 4 - 5
Resultados (3892) Página 1 - 2 - 3 - 4 - 5
I have tried the substr() but it has no effect on it. 我试过了substr(),但是对它没有影响。 The only thing I want is the number 3892. Also i would like to get rid of the lines before the output is completed.
我唯一想要的是数字3892。另外,在输出完成之前,我也想摆脱这些行。 It goes through the loop and prints nothing for 4 or 5 lines and 3 after the output.
它遍历循环,在输出4或5行和3之后什么也不打印。
<?php
include_once 'simple_html_dom.php';
error_reporting(E_ERROR);
$html = file_get_html('http://www.seccionamarilla.com.mx/resultados/hospitales/distrito-federal/1');
$results=$html->find('div.folios div.paginas',0)->plaintext;
preg_match('/\((\d+)\)/',$results, $matches);
$pages=(int)$matches[1];
echo $pages;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.