views:

73

answers:

3

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

+1  A: 

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);
}
David Zaslavsky
A: 
<?php
   preg_match('/^([^\s@\(\)])/', $string_from_author_tag, $matches);
   $matches[0];// has what you want
?>
singpolyma
A: 

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.

scraimer