Anyone good with Regular Expressions? Particularly PHP's preg_match()?

Discussion in 'Web Design and Development' started by radiantm3, Jun 24, 2008.

  1. radiantm3 macrumors 65816

    radiantm3

    Joined:
    Oct 16, 2005
    Location:
    San Jose, CA
    #1
    I know this is probably simple, but I'm not a programmer and regular expressions scare me. I've been trying to figure it out for awhile now with no luck.

    I'm trying to parse an XML file from flickr:
    Code:
    http://farm4.static.flickr.com/[b][color=red]3259/2579569358_77ddbf7068[/color][/b]_s.jpg
    Basically I need the part in red stored as a variable. Any ideas?
     
  2. dtyson macrumors member

    Joined:
    Jan 20, 2008
    #2
    You should be able to grab that by just using the substr() function.

    Code:
    <?php
    $url = "http://farm4.static.flickr.com/3259/2579569358_77ddbf7068_s.jpg";
    $new_url = substr($url, 31, -6);
    echo "$new_url";
    ?>
    
    no frills, just what ya need. What's happening here is that the $new_url variable using the substr() function is looking at the $url string and grabbing everything in it starting at the 31st position through the end of the string (minus the last 6 characters).

    Good luck.
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    Here's a regular expression approach:
    Code:
    [B][0-9]+\/[0-9]+_[0-9a-f]+[/B]
    You can try this out on my regular expression page that I created for testing out just this type of thing. I made the expression somewhat flexible because I wasn't sure if the URL would ever vary. If you need further refinement let me know.

    So if you're using PHP you can do:
    PHP:
    $url "http://farm4.static.flickr.com/3259/2579569358_77ddbf7068_s.jpg";
    $reg '/[0-9]+\/[0-9]+_[0-9a-f]+/';
    preg_match($reg$url$matches);
    echo 
    $matches[0]; // shows what was matched '3259/2579569358_77ddbf7068'
     
  4. radiantm3 thread starter macrumors 65816

    radiantm3

    Joined:
    Oct 16, 2005
    Location:
    San Jose, CA
    #4
    Thanks guys. But I'm not sure if that helps me just yet. I don't have that url to place in a variable. It needs to be scraped from the RSS feed and I need to use preg_match to find it.

    I'm basically hacking a wordpress plugin that uses magpie rss:
    Code:
    	$flickr = fetch_rss($rss);
    
    	if ($userid != '') {
    		foreach ( $flickr->items as $foto ) {
    			preg_match('/flickr\.com\/(\w.*)_s\.jpg/', $matches);
    			$thumb = 'http://farm4.static.flickr.com/'.$matches[1].'_o.jpg';
    		}
    	}
    
    Keep in mind I stripped out the code that wasn't necessary to get help and the regular expression code probably doesn't make any sense right now. :p Basically I'm building html and that $thumb variable is vital.
     
  5. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #5
    Can you supply what the RSS is (like the XML or whatever $flickr and $rss get assigned)? Feeling kind of blind here with your request. Can't match something unless we know the context.
     
  6. rfoap macrumors member

    rfoap

    Joined:
    Apr 10, 2005
    #6
    You were close, try this:
    PHP:
        $flickr fetch_rss($rss);

        if (
    $userid != '') {
            foreach ( 
    $flickr->items as $foto ) {
                
    preg_match("/flickr\.com\/([0-9]+\/[0-9]+_[0-9a-f]+)_s\.jpg/"$foto$matches);
    $thumb "http://farm4.static.flickr.com/" $matches[1] . "_o.jpg";
            }
        }
    This should work assuming your $foto variable has just one photo URL in it, otherwise use preg_match_all to match all photo URLs and then loop through that array to do what you want with those matched URLs. Here is an example you can use to see what is going on:

    PHP:
    <?php

    $foto 
    "http://farm4.static.flickr.com/3259/2579569358_77ddbf7068_s.jpg ubeoalu e http://farm4.static.flickr.com/3259/2579569358_77ddbf7000_s.jpg 
    ubeou http://farm4.static.flickr.com/3259/2579569358_77ddbf7011_s.jpg"
    ;

    preg_match_all("/flickr\.com\/([0-9]+\/[0-9]+_[0-9a-f]+)_s\.jpg/"$foto$matches);

    ?>
    <pre>
    <?php 

    echo $foto "\n\n";
    print_r($matches);
    echo 
    "\n";

    foreach (
    $matches[1] as $match)
    {
        
    $thumb "http://farm4.static.flickr.com/" $match "_o.jpg";
        echo 
    $thumb ."\n\n";
    }

    // Outputs:
    // http://farm4.static.flickr.com/3259/2579569358_77ddbf7068_o.jpg
    // http://farm4.static.flickr.com/3259/2579569358_77ddbf7000_o.jpg
    // http://farm4.static.flickr.com/3259/2579569358_77ddbf7011_o.jpg

    ?>
    </pre>



    I would try the first example, but if you had to parse the entire RSS feed as one string (replace $foto with the result of a RSS file grab) and use preg_match_all and get all the image URLs at once, then loop through to print them out, or whatever your end use is.
     
  7. radiantm3 thread starter macrumors 65816

    radiantm3

    Joined:
    Oct 16, 2005
    Location:
    San Jose, CA
    #7
    $flickr is the variable for the feed url:
    Code:
    $rss = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $userid . '&format=rss_200';
    
    I only need to pull an image url from each item in the feed:
    Code:
    <item>
    			<title>Tigers</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579568998/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579568998/" title="Tigers"><img src="http://farm4.static.flickr.com/3274/2579568998_b6837bb1a6_m.jpg" width="240" height="160" alt="Tigers" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:47:58 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T15:25:14-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579568998</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3274/2579568998_4a71bf083c_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Tigers</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3274/2579568998_b6837bb1a6_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals tiger sanfranciscozoo</media:category>
    
    
    		</item>
    
    I need to scrape and display these images:

    Code:
    http://farm4.static.flickr.com/3274/2579568998_b6837bb1a6_s.jpg
     
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    If you go to the link I provided earlier and put in the XML text you posted and put in the regular expression I gave earlier you'll see there is 3 matches (I just updated that linked page to handle tags better). Are those what you need? If so then you can use the PHP I provided before with the $matches variable holding 3 elements.

    Edit: Actually my previous PHP needs updating as rfoap referenced using preg_match_all to get all matches. The below code will print the 3 matches found. $url is assumed to be a string consisting of the XML text provided earlier.

    PHP:
    $reg '/[0-9]+\/[0-9]+_[0-9a-f]+/';
    preg_match_all($reg$url$matches);
    echo 
    $matches[0][0] . "<br />";
    echo 
    $matches[0][1] . "<br />";
    echo 
    $matches[0][2] . "<br />";
    Also it crossed my mind that among the three matches you're only worried about the one with _s at the end. In this case you would do
    PHP:
    $reg '/([0-9]+\/[0-9]+_[0-9a-f]+)_s/';
    preg_match_all($reg$url$matches);
    echo 
    $matches[1][0] . "<br />";
    which updated the regular expression slightly and changes which array element you look at in $matches.
     
  9. radiantm3 thread starter macrumors 65816

    radiantm3

    Joined:
    Oct 16, 2005
    Location:
    San Jose, CA
    #9
    I really really appreciate all the help angelwatt. Your expression works and your regex app is really cool. Here's where I'm at.

    PHP:
    function rss_stream_flickr($userid '') {
        global 
    $lifestream;
        
        
    $rss 'http://api.flickr.com/services/feeds/photos_public.gne?id=' $userid '&format=rss_200';

        
    $flickr fetch_rss($rss);

        if (
    $userid != '') {
            foreach ( 
    $flickr->items as $foto ) {
                
    $msg $foto['title'];
                
    $date strtotime($foto['pubdate']);
                
    $link $foto['link'];
          if(
    preg_match('/([0-9]+\/[0-9]+_[0-9a-f]+)_s/'$url$matches)){
            
    $thumb '<img src="http://farm4.static.flickr.com/'.$matches[1].'.jpg" width="75" height="75" alt="'.$msg.'" />';
            }
                
    $lifestream[$date]['date'] = $date;
                
    $lifestream[$date]['type'] = 'flickr';              
                
    $lifestream[$date]['link'] = $link;
                
          
    $lifestream[$date]['msg'] = '<a href="'.$link.'" class="flickr-link">'.$thumb.''.$msg.'</a>';
            }
        }
    }
    Here's the full feed:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <rss version="2.0"
            xmlns:media="http://search.yahoo.com/mrss/"
    	    xmlns:dc="http://purl.org/dc/elements/1.1/"
    	    xmlns:flickr="http://flickr.com/services/feeds/"
            >
    	<channel>
    		<title>Uploads from Mark Jardine</title>
    		<link>http://www.flickr.com/photos/radiantmark/</link>
     		<description></description>
    		<pubDate>Sat, 14 Jun 2008 19:48:09 -0800</pubDate>
    		<lastBuildDate>Sat, 14 Jun 2008 19:48:09 -0800</lastBuildDate>
    
    		<generator>http://www.flickr.com/</generator>
    		<image>
    			<url>http://farm1.static.flickr.com/52/buddyicons/18325456@N00.jpg?1195028810#18325456@N00</url>
    			<title>Uploads from Mark Jardine</title>
    			<link>http://www.flickr.com/photos/radiantmark/</link>
    		</image>
    
    		<item>
    			<title>Tigers</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579569358/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579569358/" title="Tigers"><img src="http://farm4.static.flickr.com/3259/2579569358_77ddbf7068_m.jpg" width="240" height="160" alt="Tigers" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:48:09 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T15:26:10-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579569358</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3259/2579569358_9ecccaa322_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Tigers</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3259/2579569358_77ddbf7068_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals tiger sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Tigers</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579568998/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579568998/" title="Tigers"><img src="http://farm4.static.flickr.com/3274/2579568998_b6837bb1a6_m.jpg" width="240" height="160" alt="Tigers" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:47:58 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T15:25:14-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579568998</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3274/2579568998_4a71bf083c_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Tigers</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3274/2579568998_b6837bb1a6_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals tiger sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Tigers</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579568648/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579568648/" title="Tigers"><img src="http://farm4.static.flickr.com/3104/2579568648_07a54afa88_m.jpg" width="240" height="160" alt="Tigers" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:47:47 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T15:25:08-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579568648</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3104/2579568648_3682af64be_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Tigers</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3104/2579568648_07a54afa88_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals tiger sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Tigers</title>
    			<link>http://www.flickr.com/photos/radiantmark/2578738031/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2578738031/" title="Tigers"><img src="http://farm4.static.flickr.com/3046/2578738031_94c59d6c56_m.jpg" width="240" height="160" alt="Tigers" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:47:36 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T15:24:58-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2578738031</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3046/2578738031_aaeff2f3a7_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Tigers</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3046/2578738031_94c59d6c56_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals tiger sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Tigers</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579567904/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579567904/" title="Tigers"><img src="http://farm4.static.flickr.com/3072/2579567904_40a54b191a_m.jpg" width="240" height="160" alt="Tigers" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:47:26 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T15:24:56-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579567904</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3072/2579567904_19b180dd36_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Tigers</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3072/2579567904_40a54b191a_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals tiger sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Tigers</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579567566/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579567566/" title="Tigers"><img src="http://farm4.static.flickr.com/3083/2579567566_2abc1fc966_m.jpg" width="240" height="160" alt="Tigers" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:47:15 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T15:24:52-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579567566</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3083/2579567566_f43d699010_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Tigers</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3083/2579567566_2abc1fc966_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals tiger sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Tigers</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579567174/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579567174/" title="Tigers"><img src="http://farm4.static.flickr.com/3172/2579567174_c2b6b1ceaa_m.jpg" width="240" height="160" alt="Tigers" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:47:05 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T15:24:47-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579567174</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3172/2579567174_271151828f_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Tigers</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3172/2579567174_c2b6b1ceaa_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals tiger sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Cub</title>
    			<link>http://www.flickr.com/photos/radiantmark/2578736507/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2578736507/" title="Cub"><img src="http://farm4.static.flickr.com/3007/2578736507_db92e3335f_m.jpg" width="240" height="160" alt="Cub" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:46:53 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T15:22:20-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2578736507</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3007/2578736507_e9eac4beff_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Cub</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3007/2578736507_db92e3335f_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals tiger sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Don't take me away...</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579566486/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579566486/" title="Don't take me away..."><img src="http://farm4.static.flickr.com/3194/2579566486_20a71ec515_m.jpg" width="240" height="160" alt="Don't take me away..." /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:46:45 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T15:12:39-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579566486</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3194/2579566486_937641dca3_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Don't take me away...</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3194/2579566486_20a71ec515_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals koala sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Play the kangaroo song</title>
    			<link>http://www.flickr.com/photos/radiantmark/2578735901/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2578735901/" title="Play the kangaroo song"><img src="http://farm4.static.flickr.com/3136/2578735901_4d6403ecd1_m.jpg" width="240" height="160" alt="Play the kangaroo song" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:46:36 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T15:07:23-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2578735901</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3136/2578735901_7d2aacdbf0_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Play the kangaroo song</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3136/2578735901_4d6403ecd1_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals kangaroo sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Yes, I had a small role in Lost</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579565818/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579565818/" title="Yes, I had a small role in Lost"><img src="http://farm4.static.flickr.com/3102/2579565818_7902ffd018_m.jpg" width="240" height="160" alt="Yes, I had a small role in Lost" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:46:27 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T14:37:30-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579565818</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3102/2579565818_2caa7154e7_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Yes, I had a small role in Lost</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3102/2579565818_7902ffd018_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals polarbear sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>King</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579565616/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579565616/" title="King"><img src="http://farm4.static.flickr.com/3067/2579565616_eec1eb84a5_m.jpg" width="240" height="160" alt="King" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:46:21 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T14:23:52-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579565616</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3067/2579565616_4eff23aaeb_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>King</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3067/2579565616_eec1eb84a5_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals lion sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Penguins</title>
    			<link>http://www.flickr.com/photos/radiantmark/2578735035/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2578735035/" title="Penguins"><img src="http://farm3.static.flickr.com/2399/2578735035_bf40a672b0_m.jpg" width="240" height="160" alt="Penguins" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:46:11 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T14:19:54-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2578735035</guid>
    
                                			<media:content url="http://farm3.static.flickr.com/2399/2578735035_c4cf0194e2_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Penguins</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm3.static.flickr.com/2399/2578735035_bf40a672b0_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals penguin sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Otters</title>
    			<link>http://www.flickr.com/photos/radiantmark/2578734653/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2578734653/" title="Otters"><img src="http://farm4.static.flickr.com/3014/2578734653_c5467be330_m.jpg" width="240" height="160" alt="Otters" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:46:01 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T14:17:21-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2578734653</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3014/2578734653_08edc5c441_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Otters</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3014/2578734653_c5467be330_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals otter sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Otters</title>
    			<link>http://www.flickr.com/photos/radiantmark/2578734361/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2578734361/" title="Otters"><img src="http://farm4.static.flickr.com/3041/2578734361_9f13522854_m.jpg" width="240" height="160" alt="Otters" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:45:52 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T14:17:12-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2578734361</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3041/2578734361_612023b5e1_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Otters</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3041/2578734361_9f13522854_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals otter sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>I see you</title>
    			<link>http://www.flickr.com/photos/radiantmark/2578733977/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2578733977/" title="I see you"><img src="http://farm4.static.flickr.com/3098/2578733977_70a15242eb_m.jpg" width="240" height="160" alt="I see you" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:45:41 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T14:15:27-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2578733977</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3098/2578733977_cae53b0619_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>I see you</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3098/2578733977_70a15242eb_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Gorilla</title>
    			<link>http://www.flickr.com/photos/radiantmark/2578733629/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2578733629/" title="Gorilla"><img src="http://farm4.static.flickr.com/3277/2578733629_da1248a56f_m.jpg" width="240" height="160" alt="Gorilla" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:45:30 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T14:08:30-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2578733629</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3277/2578733629_9d004acb38_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Gorilla</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3277/2578733629_da1248a56f_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals gorilla sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Gorilla</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579563524/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579563524/" title="Gorilla"><img src="http://farm4.static.flickr.com/3065/2579563524_2ccb28d843_m.jpg" width="240" height="160" alt="Gorilla" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:45:18 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T14:05:40-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579563524</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3065/2579563524_951b8cb3ef_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Gorilla</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3065/2579563524_2ccb28d843_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals gorilla sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Feed me mom</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579563180/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579563180/" title="Feed me mom"><img src="http://farm4.static.flickr.com/3043/2579563180_659a5158ce_m.jpg" width="240" height="160" alt="Feed me mom" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:45:07 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T14:01:40-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579563180</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3043/2579563180_24c2be37e2_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Feed me mom</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3043/2579563180_659a5158ce_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals giraffe sanfranciscozoo</media:category>
    
    
    		</item>
    		<item>
    			<title>Wish I was taller</title>
    			<link>http://www.flickr.com/photos/radiantmark/2579562962/</link>
    			<description><p><a href="http://www.flickr.com/people/radiantmark/">Mark Jardine</a> posted a photo:</p>
    
    <p><a href="http://www.flickr.com/photos/radiantmark/2579562962/" title="Wish I was taller"><img src="http://farm4.static.flickr.com/3125/2579562962_a7a2dffe53_m.jpg" width="240" height="160" alt="Wish I was taller" /></a></p>
    
    <p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></description>
    			<pubDate>Sat, 14 Jun 2008 19:45:00 -0800</pubDate>
    			                        <dc:date.Taken>2008-06-14T14:01:30-08:00</dc:date.Taken>
                			<author flickr:profile="http://www.flickr.com/people/radiantmark/">nobody@flickr.com (Mark Jardine)</author>
    			<guid isPermaLink="false">tag:flickr.com,2004:/photo/2579562962</guid>
    
                                			<media:content url="http://farm4.static.flickr.com/3125/2579562962_3f107bce71_o.jpg" 
    				       type="image/jpeg"
    				       height="1064"
    				       width="1600"/>
            <media:title>Wish I was taller</media:title>
                <media:description type="html"><p>Photos taken at the SF Zoo.  Photos taken with my Rebel XT and EF 70-200mm f/4l IS.</p></media:description>
            <media:thumbnail url="http://farm4.static.flickr.com/3125/2579562962_a7a2dffe53_s.jpg" height="75" width="75" />
            <media:credit role="photographer">Mark Jardine</media:credit>
    		<media:category scheme="urn:flickr:tags">animals giraffe sanfranciscozoo</media:category>
    
    
    		</item>
    
    	</channel>
    </rss>
    
    Everything works except for this part. And I know your expression works, so it must have something to do with the array itself?

    PHP:
    if(preg_match('/([0-9]+\/[0-9]+_[0-9a-f]+)_s/'$url$matches)){ 
            
    $thumb '<img src="http://farm4.static.flickr.com/'.$matches[1].'.jpg" width="75" height="75" alt="'.$msg.'" />'
            }
    Again, I totally appreciate your help and of course it's not expected.
     
  10. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #10
    I don't see where you assign anything to $url. That's likely the issue. You might use $foto instead, but I can't tell from just the code. $url would need to be whatever variable has the text inside the item tag.
     
  11. radiantm3 thread starter macrumors 65816

    radiantm3

    Joined:
    Oct 16, 2005
    Location:
    San Jose, CA
    #11
    Yea $url shouldn't be there. Thanks for helping me with the rexex issue. You did answer my original question. I'll just try to figure this array/variable issue out.
     

Share This Page