php - php从网页解析字符串
问题描述
是否有替代代码可以忽略
<td *******>1234</td>
我只需要 1234 并且可以忽略 td 字符串。
// 现在我正在剥离字符串,但在现场情况下,这个字符串也可以更改,所以我被卡住了。
$searchString = '<td style="font-weight: bold; font-size:15px; text-align:left;">Pakistan</td>';
$i=1;
foreach($stringArr as $key) {
if( strpos( $key, $searchString ) !== false )
$LineNum = $i;
$i++;
}
$LineNum = $LineNum-1;
$Country = trim($stringArr[$LineNum]); //get the third line
$TotalCases = trim($stringArr[$LineNum+1]); //get the third line
$NewCases = trim($stringArr[$LineNum+2]); //get the third line
$TotalDeaths = trim($stringArr[$LineNum+3]); //get the third line
$NewDeaths = trim($stringArr[$LineNum+4]); //get the third line
$TotalRecovered = trim($stringArr[$LineNum+5]); //get the third line
$ActiveCases = trim($stringArr[$LineNum+6]); //get the third line
$Serious_Critical = trim($stringArr[$LineNum+7]); //get the third line
$Tot_Cases_1M_pop = trim($stringArr[$LineNum+8]); //get the third line
$Deaths_1M_pop = trim($stringArr[$LineNum+9]); //get the third line
$Reported_1st_case = trim($stringArr[$LineNum+10]); //get the third line
$Country = substr($Country, 64); // for now i am stripping the string but on live case this string can be changed as well so i am stuck.
$Country = substr($Country,0,-5);
$TotalCases = substr($TotalCases, 48);
$TotalCases = substr($TotalCases,0,-5);
if($NewCases == "<td style=\"font-weight: bold; text-align:right;\"></td>")
{
$NewCases = 0;
}else{
$NewCases = substr($NewCases, 74);
}
解决方案
strip_tags 将删除 html 标签
推荐阅读
- c# - 无法从“字符串”转换为“Microsoft.EntityFrameworkCore.ServerVersion”
- javascript - 从 React Select 中的选择对象中获取值
- python - Python:Pandas df 的线性回归 - 序数日期转换
- mongodb - 用于计算百分比的 MongoDB 查询
- python - 如何修复 Django 测试中的内存泄漏?
- python - 它的数据集“忠实”默认预加载在任何库中?
- python - 预期 min_ndim=4,在 tensorflow 中发现 ndim=2
- asp.net-core - ASP.NET Core 路由无法匹配路由参数,API 资源管理器中的路由参数重复
- ide - PhpStorm IDE 设置同步 - SSH 配置未同步,为什么?
- visual-c++ - 两种方式有什么区别?以及如何通过每种方式保存代码?