0

Twitter 的 RSS 提要显示名称为:

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

有没有办法使用 php 或 javascript(最好是 jquery)来删除从第一个括号开始的所有内容?我只想显示用户名,而不是用户名和人的真实姓名。

其他详细信息:我正在使用 SimplePie 将 RSS 提要解析为页面

4

3 回答 3

1

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

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);
}
于 2009-03-15T03:46:26.713 回答
0
<?php
   preg_match('/^([^\s@\(\)])/', $string_from_author_tag, $matches);
   $matches[0];// has what you want
?>
于 2009-03-15T22:01:03.807 回答
0

也许看看Yahoo Pipes - 它可用于将 RSS 提要修改为可以做任何事情的后处理 RSS 提要,包括 REGEX 搜索和替换。

于 2009-03-15T22:34:19.747 回答