Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何";使用「;PHP函数中的HTML特殊字符,比如strpos?_Php_Html_Htmlspecialchars - Fatal编程技术网

如何";使用「;PHP函数中的HTML特殊字符,比如strpos?

如何";使用「;PHP函数中的HTML特殊字符,比如strpos?,php,html,htmlspecialchars,Php,Html,Htmlspecialchars,我有一个问题,就是我不能使用php字符串函数,比如substr、strpos等,以及诸如middledot之类的HTML特殊字符 我的具体问题是: $tdp = gettexts('TDP: ' , '•' , $complete_info); 函数为我提供一个文本片段: function gettexts ($startst, $endst, $content){ $first_step = explode($startst , $content); $second_step

我有一个问题,就是我不能使用php字符串函数,比如substr、strpos等,以及诸如middledot之类的HTML特殊字符

我的具体问题是:

$tdp = gettexts('TDP: ' , '•' , $complete_info);
函数为我提供一个文本片段:

function gettexts ($startst, $endst, $content){
    $first_step = explode($startst , $content);
    $second_step = explode($endst , $first_step[1]);
    $textst= $second_step[0];
    return $textst;
}
不起作用。 我怎样才能解决这个问题

编辑: 当我使用以下代码测试它时,它会工作:

$turbo = gettexts('Turbo: ' , '•' , 'Turbo: 4.70GHz • TDP: 220W • Fertigung: 32nm •');
这是我想读的一页:

这里有一个完整的测试代码。turbo频率的结果应该是3.60(我不能使用Ghz,因为有时候它的turbo:N/A,我真的想用点来爆炸;)

编辑:

所以,你正在废弃一个页面,想要提取一些信息。 如果复制粘贴,我以前的代码可以工作,但要获取网页,存在编码问题(该网页是cp1252编码的,但没有标题)

您应该解析dom(在修复编码头之后)并使用xpath提取内容。。。但是为了基于代码的快速修复,只需删除strip_标记并使用my函数

在下载页面之前和之后查看源代码,您会注意到,如果使用strip_标记,htm实体将消失

这将有助于:

function gettexts ($startst, $endst, $content){
    $first_step = explode(html_entity_decode($startst) , html_entity_decode($content));
    $second_step = explode(html_entity_decode($endst), $first_step[1]);
    $textst= $second_step[0];
    return $textst;
}

$content = file_get_contents('http://geizhals.eu/intel-core-i7-6700t-cm8066201920202-a1261888.html');
$string = gettexts('<div id="gh_proddesc">' ,'Gelistet seit:' , $content);

echo 'Frequency:'. $frequency = gettexts('Taktfrequenz: ' , 'GHz' , $string);
echo '<br>';
echo 'Turbo-Frequency:'.$turbo = gettexts('Turbo: ' , '&#149;' , $string);
函数gettexts($startst、$endst、$content){ $first_step=explode(html_entity_decode($startst),html_entity_decode($content)); $second_step=explode(html_entity_decode($endst),$first_step[1]); $textst=$second_step[0]; 返回$textst; } $content=file\u get\u contents('http://geizhals.eu/intel-core-i7-6700t-cm8066201920202-a1261888.html'); $string=gettexts(“”,'Gelistet seit:',$content); 回声“频率:”$频率=gettexts('Taktfrequenz:','GHz',$string); 回声“
”; 回显“Turbo-Frequency:”.$Turbo=gettexts('Turbo:','•;',$string);
你能发布一个$complete_info的示例吗?complete_info=Octa Core:“Vishera”•Taktfrequenz:4.40GHz,Turbo:4.70GHz•TDP:220W…..在我的回答中添加的工作代码对我不起作用。没有检测到中间点。我尝试了一下,但结果相同。我在最初的帖子中添加了一个测试代码。使用原始url。当它起作用时,我接受这个解决方案:DWork!谢谢。但我现在使用的是html解析器,但它也只适用于•;'因此,您的解决方案非常有用。谢谢。
function gettexts ($startst, $endst, $content){
    $first_step = explode(html_entity_decode($startst) , html_entity_decode($content));
    $second_step = explode(html_entity_decode($endst), $first_step[1]);
    $textst= $second_step[0];
    return $textst;
}

$content = file_get_contents('http://geizhals.eu/intel-core-i7-6700t-cm8066201920202-a1261888.html');
$string = gettexts('<div id="gh_proddesc">' ,'Gelistet seit:' , $content);

echo 'Frequency:'. $frequency = gettexts('Taktfrequenz: ' , 'GHz' , $string);
echo '<br>';
echo 'Turbo-Frequency:'.$turbo = gettexts('Turbo: ' , '&#149;' , $string);