以下是简单的html我想删除所有span标签,只想要0.65值。请有人帮我这个。
<span class="smw smw-inline smw-basic smw-ct-default smw-visible" data-symbol="GSD.V" data-type="inline" data-refresh-frequency="5" data-source="live">
<span class="smw-market-data-field smw-field-l1" data-field="l1">0.65</span>
</span>
答案 0 :(得分:2)
您可以使用preg_replace('/<[^>]*>/', '', $content);
此外,您只能使用以下内容删除范围代码preg_replace('/<span[^>]+\>/i', '', $content);
:
<?php
$content = '<div><span class="smw smw-inline smw-basic smw-ct-default smw-visible" data-symbol="GSD.V" data-type="inline" data-refresh-frequency="5" data-source="live">
<span class="smw-market-data-field smw-field-l1" data-field="l1">0.65</span>
</span></div>';
echo $string = preg_replace('/<[^>]*>/', '', $content);
echo $new_string = preg_replace('/<span[^>]+\>/i', '', $content);
?>
答案 1 :(得分:0)
我假设PHP和Perl足够相似......
s{\</?span[^>]*/?>}{}gism
HTH
答案 2 :(得分:0)
您可以使用preg_replace
和正则表达式执行此操作:
<?php
$html = '<span class="smw smw-inline smw-basic smw-ct-default smw-visible" data-symbol="GSD.V" data-type="inline" data-refresh-frequency="5" data-source="live">
<span class="smw-market-data-field smw-field-l1" data-field="l1">0.65</span>
</span>';
$without_span = $html;
$without_span = preg_replace('#\n\r#', '', $without_span);
$without_span = preg_replace('#\n#', '', $without_span);
while(preg_match_all('#(<span.*?>)(.*?)(</span>)#', $without_span)) {
$without_span = preg_replace('#(<span.*?>)(.*?)(</span>)#', '$2', $without_span);
}
print_r($without_span);
答案 3 :(得分:0)
请尝试以下代码。
$string = '<span class="smw smw-inline smw-basic smw-ct-default smw-visible" data-symbol="GSD.V" data-type="inline" data-refresh-frequency="5" data-source="live">
<span class="smw-market-data-field smw-field-l1" data-field="l1">0.65</span>
</span>';
echo strip_tags($string);