从 RSS 描述中删除不在标签元素内的文本
Remove text from RSS description that is not within a tag element
我想从不在标签元素(即 strong、p、span 等)内的 RSS 描述中删除文本。我能够删除 strong 元素,但我做不到定位 "Location" 文本,因为它不在标签内。
为了澄清,我正在尝试删除
21.671N 158.117W or 5 nautical miles N of search location of 21.5928N 158.1034W.
我无法定位字符串,因为每个 Feed 都不同。另外,我尝试将 span 标签应用于任何没有运气的文本。
下面是我的代码...
<?php
$rss = simplexml_load_file('http://www.ndbc.noaa.gov/rss/ndbc_obs_search.php?lat=21.5928&lon=-158.1034&radius=100');
$i = 0;
foreach($rss->channel->item as $item) {
echo "<p>" . $item->description . "</p>";
echo '<h2><a style="font-size:12px; text-decoration:none;" href="'. $item- >link .'">' . $item->title . "</a></h2>";
$i++;
if ($i >= 1){
break;
}
}
?>
<script>
document.getElementsByTagName("strong")[1].setAttribute("hidden", true);
</script>
在此先感谢您的帮助。
似乎此提要总是将 'location' 项目作为第二行;您可以在 <br />
上拆分,删除第二行,然后再次与 <br />
合并。
例如
foreach($rss->channel->item as $item) {
// Split on <br />
$descriptionBits = explode("<br />", $item->description);
// Remove the location line
unset($descriptionBits[1]);
// Glue the bits back together again
$descriptionString = implode("<br />", $descriptionBits);
// Then print it out
echo "<p>" . $descriptionString . "</p>";
我想从不在标签元素(即 strong、p、span 等)内的 RSS 描述中删除文本。我能够删除 strong 元素,但我做不到定位 "Location" 文本,因为它不在标签内。
为了澄清,我正在尝试删除
21.671N 158.117W or 5 nautical miles N of search location of 21.5928N 158.1034W.
我无法定位字符串,因为每个 Feed 都不同。另外,我尝试将 span 标签应用于任何没有运气的文本。
下面是我的代码...
<?php
$rss = simplexml_load_file('http://www.ndbc.noaa.gov/rss/ndbc_obs_search.php?lat=21.5928&lon=-158.1034&radius=100');
$i = 0;
foreach($rss->channel->item as $item) {
echo "<p>" . $item->description . "</p>";
echo '<h2><a style="font-size:12px; text-decoration:none;" href="'. $item- >link .'">' . $item->title . "</a></h2>";
$i++;
if ($i >= 1){
break;
}
}
?>
<script>
document.getElementsByTagName("strong")[1].setAttribute("hidden", true);
</script>
在此先感谢您的帮助。
似乎此提要总是将 'location' 项目作为第二行;您可以在 <br />
上拆分,删除第二行,然后再次与 <br />
合并。
例如
foreach($rss->channel->item as $item) {
// Split on <br />
$descriptionBits = explode("<br />", $item->description);
// Remove the location line
unset($descriptionBits[1]);
// Glue the bits back together again
$descriptionString = implode("<br />", $descriptionBits);
// Then print it out
echo "<p>" . $descriptionString . "</p>";