Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 5th, 2009, 03:44 PM
jleagle's Avatar
jleagle jleagle is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 228 jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 12 h 16 m 10 sec
Reputation Power: 25
Send a message via MSN to jleagle
Tricky PHP preg_replace

I’m trying to edit a RSS feed so the syntax is compatible with a RSS parsing script my site uses. Here is the RSS feed.
Here are the two strings which I need to edit:

<media:content width="1600" url="http://lh3.ggpht.com/_YcQ1Dmq5PFY/SL-wC7SQVII/AAAAAAAAC6Q/NpfNgIZZDTA/s1600/DSC00242.JPG" medium="image" type="image/jpeg" height="1200"/>

<media:thumbnail width="288" url="http://lh3.ggpht.com/_YcQ1Dmq5PFY/SL-wC7SQVII/AAAAAAAAC6Q/NpfNgIZZDTA/s288/DSC00242.JPG" height="216"/>

I need to change them so they appear as:

<content>http://lh3.ggpht.com/_YcQ1Dmq5PFY/SL-wC7SQVII/AAAAAAAAC6Q/NpfNgIZZDTA/s1600/DSC00242.JPG</content>

<thumbnail>http://lh3.ggpht.com/_YcQ1Dmq5PFY/SL-wC7SQVII/AAAAAAAAC6Q/NpfNgIZZDTA/s288/DSC00242.JPG</thumbnail>

I’ve been trying for a long time now and have come up with a hideous mess of PHP!
Any ideas? Thanks.
__________________
JimEagle.com

Last edited by jleagle : April 5th, 2009 at 03:50 PM.

Reply With Quote
  #2  
Old April 5th, 2009, 04:11 PM
ptr2void ptr2void is offline
I haz teh codez!
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Dec 2003
Posts: 2,511 ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 35 m 41 sec
Reputation Power: 2274
How about this?
php Code:
Original - php Code
  1. <?php
  2.  
  3. $content = '<media:content width="1600" url="http://lh3.ggpht.com/_YcQ1Dmq5PFY/SL-wC7SQVII/AAAAAAAAC6Q/NpfNgIZZDTA/s1600/DSC00242.JPG" medium="image" type="image/jpeg" height="1200"/>';
  4. $thumbnail = '<media:thumbnail width="288" url="http://lh3.ggpht.com/_YcQ1Dmq5PFY/SL-wC7SQVII/AAAAAAAAC6Q/NpfNgIZZDTA/s288/DSC00242.JPG" height="216"/>';
  5. echo preg_replace('/^<media:(content|thumbnail)\s.*url="([^\s"]+).*/', '<$1>$2</$1>', $content) . "\n";
  6. echo preg_replace('/^<media:(content|thumbnail)\s.*url="([^\s"]+).*/', '<$1>$2</$1>', $thumbnail);
  7.  
  8. ?>
__________________
I ♥ ManiacDan & requinix

This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!

Reply With Quote
  #3  
Old April 5th, 2009, 04:18 PM
jleagle's Avatar
jleagle jleagle is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 228 jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 12 h 16 m 10 sec
Reputation Power: 25
Send a message via MSN to jleagle
Thanks for the quick reply, i should have mentioned how i was fetching the feed. Here is my script:
php Code:
Original - php Code
  1. <?php
  2. $rss = file_get_contents('http://pipes.yahoo.com/pipes/pipe.run?XML=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Fjimeagle%2Falbumid%2F'.$  _GET['a'].'%3Fthumbsize%3D288%26imgmax%3D1600&_id=_ps93kMh3hGd_2Ub3nBDOQ&_render=rss&itemname=entry');
  3. $rss = preg_replace('/^<media:(content|thumbnail)\s.*url="([^\s"]+).*/', '<$1>$2</$1>', $rss) . "\n";
  4. $rss = preg_replace('/^<media:(content|thumbnail)\s.*url="([^\s"]+).*/', '<$1>$2</$1>', $rss);
  5. echo $rss;
  6. ?>


I tried to adapt the code you gave me but it didnt work. I am hosting it here.

Last edited by jleagle : April 5th, 2009 at 04:22 PM.

Reply With Quote
  #4  
Old April 5th, 2009, 07:00 PM
ptr2void ptr2void is offline
I haz teh codez!
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Dec 2003
Posts: 2,511 ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level)ptr2void User rank is General 19th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 35 m 41 sec
Reputation Power: 2274
OK, how about this then?
php Code:
Original - php Code
  1. $fp = file('http://jimeagle.com/site/pictures_rss.php?a=5241893999118690321');
  2. foreach ($fp as $line)
  3. {
  4.     echo preg_replace('/(\s+)<media:(content|thumbnail)\s.*url="([^\s"]+).*/', '$1<$2>$3</$2>', $line);
  5. }

Reply With Quote
  #5  
Old April 5th, 2009, 07:21 PM
jleagle's Avatar
jleagle jleagle is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 228 jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level)jleagle User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 12 h 16 m 10 sec
Reputation Power: 25
Send a message via MSN to jleagle
Wow thanks alot, that works perfectly. I have been trying to do that for hours!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Tricky PHP preg_replace

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap