-3
我必须得到2 span标签之间的文本,但我不能得到它。 这是我的代码在php中的2个span标签之间获取文本
for ($idp = 2; $idp <= 2; $idp++) {
$string = "Não foi possível carregar a informação";
$urlp = "http://www.parlamento.pt/DeputadoGP/Paginas/Biografia.aspx?BID=$idp";
$content = file_get_contents($urlp);
if (strpos($content,$string) === false){
//echo $urlp;
echo "\n";
//$ins = "INSERT INTO biografias (idp, urlp) VALUES ('$idp', '$urlp')";
//$run_ins = mysqli_query($conecta, $ins);
} else {
echo 'Biografia Inexistente';
echo "\n";
}
这是HTML代码行,我需要获取文本
<span id="ctl00_ctl43_g_61a4e0fc_afd7_4b91_ba82_ccfff9f5472d_ctl00_lblNomeDeputado">**Abílio Curto**</span>
谢谢。
欢迎[这么]!在这个网站,你应该尝试**自己编写代码**。后** [做更多的研究](//meta.stackoverflow.com/questions/261592)**如果你有问题,你可以**发布你已经尝试**与清楚的解释是什么是'工作**并提供[** Minimal,Complete和Verifiable示例**](// stackoverflow.com/help/mcve)。我建议阅读[问]一个好问题和[完美问题](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。另外,一定要参加[游览]并阅读[this](// meta.stackoverflow.com/questions/347937/)**。 –
如果你只是在寻找原始文本,没有任何HTML,'strip_tags()'可能会帮助你。否则,你可能需要一个正则表达式。 – Qirel
不需要正则表达式。看看['strpos()'](http://php.net/manual/en/function.strpos.php),['strrpos()'](http://php.net/manual/en /function.strrpos.php)和['substr()'](http://php.net/manual/en/function.substr.php) – domsson