Apache2Triad Help, Support and Development Forum Index Search Profile Log in to check your private messages Log in Register Memberlist Attachments Statistics Crew/Ranks Archive
 [PHP] preg_replace patterns
Google
Post new topic Reply to topic
Author Message
Joshua Meadows (DemoRic)
support
support


Joined: 29 Dec 2004
Posts: 783
Location: S.E. Kansas

PostPosted: Fri Aug 11, 2006 12:13 am Reply with quoteBack to top

I am at a loss here I've been trying to code an rss/xml to xspf converting script for a project and I'm stumped on a pattern.
Code:
$patterns[0] = "/<item>/";
   $patterns[1] = "/<\/item>/";
   $patterns[2] = "/<title>/";
   $patterns[3] = "/<\/title>/";
   $patterns[4] = "/<guid>/";
   $patterns[5] = "/<\/guid>/";
   $patterns[6] = "/<enclosure url=/";
   $patterns[7] = "/type='(...)'>/";   

   $replacements[0] = "~new~<track>";
   $replacements[1] = "</track>";
   $replacements[2] = "<annotation>";
   $replacements[3] = "</annotation>";
   $replacements[4] = "<location>";
   $replacements[5] = "</location>";
   $replacements[6] = "<location>";
   $replacements[7] = "</location>";

   ksort($patterns);
   ksort($replacements);
   $fullfile=preg_replace($patterns, $replacements, $fullfile);

The problem I have is with wanting to change:
Quote:
<enclosure url="http://site/song.mp3" type="audio/mp3"/>

to
Quote:
<location>http://site/song.mp3</location>
View user's profileSend private messageYahoo MessengerICQ Number
cigraphics
 
 


Joined: 21 Aug 2005
Posts: 148
Location: Romania, Pitesti

PostPosted: Fri Aug 11, 2006 9:32 pm Reply with quoteBack to top

i think that you want to use something like BBCode:
Code:

<?php
function BBCode($text){
$BBCode = array("<image>" => "<img border=0 src='",
"</image>" => "' />",
"<bold>" => "<b>",
</bold>" => "</b>"
);
$parsedtext = str_replace(array_keys($BBCode), array_values($BBCode), $text);
return $parsedtext;
}
?>
View user's profileSend private messageSend e-mailYahoo Messenger
Vlad Alexa Mancini
lead developer
lead developer


Joined: 07 Jul 2003
Posts: 1539

PostPosted: Tue Aug 15, 2006 4:36 pm Reply with quoteBack to top

Code:
$input = '<enclosure url="http://site/song.mp3" type="audio/mp3"/>';

$output = preg_replace("/(.* url=\")(\S*)(\".*)/","<location>$2</location>",$input);



or

Code:
$input = '<enclosure url="http://site/song.mp3" type="audio/mp3"/>';

preg_match("/url=\"(\S*)\"/",$input,$match);

$output = "<location>".$match[1]."</location>";
View user's profileSend private message
Display posts from previous:      
Post new topic Reply to topic


 Jump to:   



View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Powered by phpBB © 2001, 2002 phpBB Group :: FI Theme
All times are GMT