从 RSS 源中删除一段文本

发布于 2024-07-15 06:35:07 字数 292 浏览 5 评论 0原文

Twitter 的 RSS 提要将名称显示为:

<name>johnDoe (John Doe)</name>

Is there a way to use php or javascript (preferred jquery) to delete everything opening with the 第一个括号及其后的内容? 我只想显示用户名,而不是用户名和该人的真实姓名。

其他细节:我正在使用 SimplePie 将 RSS 提要解析到页面中

Twitter's RSS feed displays names as:

<name>johnDoe (John Doe)</name>

Is there a way to use php or javascript (preferably jquery) to delete everything starting with the first parentheses and after? I only want to show the username and not the username and the person's actual name.

Other details: I'm parsing an RSS feed into a page using SimplePie

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海之角 2024-07-22 06:35:07

我建议像往常一样解析 RSS 提要,然后从解析的结构中获取 元素的值,找到左括号的索引,并修剪掉先前索引中的所有内容(即空间)开始。 就像是

var nameStr = ...; // get the value of <name>
var pIndex = nameStr.indexOf(" (");
if (pIndex) { // just make sure a parenthesis was in fact found
    nameStr = nameStr.substring(0, pIndex);
}

I would suggest parsing the RSS feed as usual then getting the value of the <name> element from your parsed structure, finding the index of the opening parenthesis, and trimming off everything from the previous index (i.e. the space) onwards. Something like

var nameStr = ...; // get the value of <name>
var pIndex = nameStr.indexOf(" (");
if (pIndex) { // just make sure a parenthesis was in fact found
    nameStr = nameStr.substring(0, pIndex);
}
暖心男生 2024-07-22 06:35:07
<?php
   preg_match('/^([^\s@\(\)])/', $string_from_author_tag, $matches);
   $matches[0];// has what you want
?>
<?php
   preg_match('/^([^\s@\(\)])/', $string_from_author_tag, $matches);
   $matches[0];// has what you want
?>
ㄟ。诗瑗 2024-07-22 06:35:07

也许看看 Yahoo Pipes - 它可用于将 RSS 提要修改为后处理的可以执行任何操作的 RSS 提要,包括 REGEX 搜索和搜索 代替。

Maybe have a look at Yahoo Pipes - it can be used to modify RSS feeds into a post-processed RSS feed that can do anything, including REGEX search & replace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文