Jump to content

[SOLVED] retrieving a certain image


atlanta

Recommended Posts

Hi all i need a little help my regex skills aren't too great so ..  what i need is to retrieve is

 

 

http://b1.ac-images.myspacecdn.com/00841/12/32/841492321_m.gif

 

from

 

<table id="mainLayout">
<tr>
<td id="1a" width="304" height="300">


<div id="profile_info" class="section">
<h4 class="heading">SykoRadio</h4><br />

    	

<div id="profile_info_image">			
	<a id="ctl00_cpMain_ctl01_ctl01_hlDefaultImage" rel="searchMonkey-photo" href="http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&friendID=11"><img src="http://b1.ac-images.myspacecdn.com/00841/12/32/841492321_m.gif" alt="SykoRadio"/></a>

	<center>View My: <a id="ctl00_cpMain_ctl01_ctl01_ctrlViewMorePics" rel="searchMonkey-viewPictures" href="http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&friendID=11">Pics</a>  | <a href="http://vids.myspace.com/index.cfm?fuseaction=vids.showvids&friendID=11&n=11&MyToken=5ee0978c-1539-4a01-9db5-e0268888aa3d">Videos</a> 	</center>
</div>

    <div id="profile_info_content" class="text">
	    <span id="profile_info_headline">"Sykoradio.org - Music for the Kultured"</span><br /><br />

	    Male<br />
	    30 years old<br /><br />
	    Columbus, OHIO<br />
	    United States<br />
    		
	    


<br />


    				
	    Last Login: <span class="searchMonkey-lastLogin">07/23/08</span>

    </div>

<div class="clear"></div>
</div>
    
    <div id="profile_contact" class="section">
    <h5 class="heading">Contacting SykoRadio</h5>
    <a href="http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID=11&MyToken=5ee0978c-1539-4a01-9db5-e0268888aa3d" id="ctl00_cpMain_ctl01_ctl02_MailLink" rel="searchMonkey-sendMessage"><img id="mailLinkImg" src='http://x.myspacecdn.com/modules/profiles/static/img/contact_sendmailicon.gif' alt="" />Send Message</a>
    <a href="http://messaging.myspace.com/index.cfm?fuseaction=mail.forward&friendID=11&f=forwardprofile" id="ctl00_cpMain_ctl01_ctl02_ForwardLink"><img id="forwardLinkImg" src='http://x.myspacecdn.com/modules/profiles/static/img/contact_forwardmailicon.gif' alt="" />Forward to Friend</a>

    <a href="http://friends.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=11" id="ctl00_cpMain_ctl01_ctl02_AddFriendLink" rel="searchMonkey-addToFriends"><img id="addFriendLinkImg"  src='http://x.myspacecdn.com/modules/profiles/static/img/contact_addfriendicon.gif'   alt="" />Add to Friends</a>
    <a href="http://collect.myspace.com/index.cfm?fuseaction=user.addToFavorite&friendID=11&public=0" id="ctl00_cpMain_ctl01_ctl02_AddFavoriteLink"><img id="addFavoriteLinkImg"  src='http://x.myspacecdn.com/modules/profiles/static/img/contact_addfavoritesicon.gif'  alt="" />Add to Favorites</a>
    <a href="javascript: IsMySpaceIMInstalled();" id="ctl00_cpMain_ctl01_ctl02_MessageFriendLink"><img id="messageFriendLinkImg"   src='http://x.myspacecdn.com/modules/profiles/static/img/contact_messagefriend.gif'  alt="" />IM / Call</a>
    <a href="http://friends.myspace.com/index.cfm?fuseaction=block.blockUser&userID=11" id="ctl00_cpMain_ctl01_ctl02_BlockFriendLink" onclick="return confirm('Are you sure you want to block this user?\n- to block this user, hit OK\n- otherwise, hit Cancel');"><img id="blockFriendLinkImg"  src='http://x.myspacecdn.com/modules/profiles/static/img/contact_blockuser.gif'  alt="" />Block User</a>
    <a href="http://groups.myspace.com/index.cfm?fuseaction=groups.addtogroup&friendID=11" id="ctl00_cpMain_ctl01_ctl02_AddToGroupLink"><img id="addToGroupLinkImg"  src='http://x.myspacecdn.com/modules/profiles/static/img/contact_addtogroupicon.gif'  alt="" />Add to Group</a>
    <a href="http://collect.myspace.com/index.cfm?fuseaction=RateImage.UserRating&UserID=11" id="ctl00_cpMain_ctl01_ctl02_RateFriendLink"><img id="rateFriendLinkImg"  src='http://x.myspacecdn.com/modules/profiles/static/img/contact_rankusericon.gif'  alt="" />Rank User</a>

    <div class="clear"></div>
    </div>
   

Link to comment
https://forums.phpfreaks.com/topic/137467-solved-retrieving-a-certain-image/
Share on other sites

Well, if you were to plug your code as a dochere string into the following regex pattern:

 

$str = <<<HTML
<table id="mainLayout">
<tr>
<td id="1a" width="304" height="300">


<div id="profile_info" class="section">
<h4 class="heading">SykoRadio</h4><br />

    	

<div id="profile_info_image">			
	<a id="ctl00_cpMain_ctl01_ctl01_hlDefaultImage" rel="searchMonkey-photo" href="http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&friendID=11"><img src="http://b1.ac-images.myspacecdn.com/00841/12/32/841492321_m.gif" alt="SykoRadio"/></a>

	<center>View My: <a id="ctl00_cpMain_ctl01_ctl01_ctrlViewMorePics" rel="searchMonkey-viewPictures" href="http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&friendID=11">Pics</a>  | <a href="http://vids.myspace.com/index.cfm?fuseaction=vids.showvids&friendID=11&n=11&MyToken=5ee0978c-1539-4a01-9db5-e0268888aa3d">Videos</a> 	</center>
</div>

    <div id="profile_info_content" class="text">
	    <span id="profile_info_headline">"Sykoradio.org - Music for the Kultured"</span><br /><br />

	    Male<br />
	    30 years old<br /><br />
	    Columbus, OHIO<br />
	    United States<br />
    		
	    


<br />


    				
	    Last Login: <span class="searchMonkey-lastLogin">07/23/08</span>

    </div>

<div class="clear"></div>
</div>
    
    <div id="profile_contact" class="section">
    <h5 class="heading">Contacting SykoRadio</h5>
    <a href="http://messaging.myspace.com/index.cfm?fuseaction=mail.message&friendID=11&MyToken=5ee0978c-1539-4a01-9db5-e0268888aa3d" id="ctl00_cpMain_ctl01_ctl02_MailLink" rel="searchMonkey-sendMessage"><img id="mailLinkImg" src='http://x.myspacecdn.com/modules/profiles/static/img/contact_sendmailicon.gif' alt="" />Send Message</a>
    <a href="http://messaging.myspace.com/index.cfm?fuseaction=mail.forward&friendID=11&f=forwardprofile" id="ctl00_cpMain_ctl01_ctl02_ForwardLink"><img id="forwardLinkImg" src='http://x.myspacecdn.com/modules/profiles/static/img/contact_forwardmailicon.gif' alt="" />Forward to Friend</a>

    <a href="http://friends.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=11" id="ctl00_cpMain_ctl01_ctl02_AddFriendLink" rel="searchMonkey-addToFriends"><img id="addFriendLinkImg"  src='http://x.myspacecdn.com/modules/profiles/static/img/contact_addfriendicon.gif'   alt="" />Add to Friends</a>
    <a href="http://collect.myspace.com/index.cfm?fuseaction=user.addToFavorite&friendID=11&public=0" id="ctl00_cpMain_ctl01_ctl02_AddFavoriteLink"><img id="addFavoriteLinkImg"  src='http://x.myspacecdn.com/modules/profiles/static/img/contact_addfavoritesicon.gif'  alt="" />Add to Favorites</a>
    <a href="javascript: IsMySpaceIMInstalled();" id="ctl00_cpMain_ctl01_ctl02_MessageFriendLink"><img id="messageFriendLinkImg"   src='http://x.myspacecdn.com/modules/profiles/static/img/contact_messagefriend.gif'  alt="" />IM / Call</a>
    <a href="http://friends.myspace.com/index.cfm?fuseaction=block.blockUser&userID=11" id="ctl00_cpMain_ctl01_ctl02_BlockFriendLink" onclick="return confirm('Are you sure you want to block this user?\n- to block this user, hit OK\n- otherwise, hit Cancel');"><img id="blockFriendLinkImg"  src='http://x.myspacecdn.com/modules/profiles/static/img/contact_blockuser.gif'  alt="" />Block User</a>
    <a href="http://groups.myspace.com/index.cfm?fuseaction=groups.addtogroup&friendID=11" id="ctl00_cpMain_ctl01_ctl02_AddToGroupLink"><img id="addToGroupLinkImg"  src='http://x.myspacecdn.com/modules/profiles/static/img/contact_addtogroupicon.gif'  alt="" />Add to Group</a>
    <a href="http://collect.myspace.com/index.cfm?fuseaction=RateImage.UserRating&UserID=11" id="ctl00_cpMain_ctl01_ctl02_RateFriendLink"><img id="rateFriendLinkImg"  src='http://x.myspacecdn.com/modules/profiles/static/img/contact_rankusericon.jpeg'  alt="" />Rank User</a>

    <div class="clear"></div>
    </div>
HTML;

preg_match_all('#img.+?(https?:.+?\.gif)#s', $str, $matches);
echo '<pre>'.print_r($matches[1], true);

 

Your output would be:

Array
(
    [0] => http://b1.ac-images.myspacecdn.com/00841/12/32/841492321_m.gif
    [1] => http://x.myspacecdn.com/modules/profiles/static/img/contact_sendmailicon.gif
    [2] => http://x.myspacecdn.com/modules/profiles/static/img/contact_forwardmailicon.gif
    [3] => http://x.myspacecdn.com/modules/profiles/static/img/contact_addfriendicon.gif
    [4] => http://x.myspacecdn.com/modules/profiles/static/img/contact_addfavoritesicon.gif
    [5] => http://x.myspacecdn.com/modules/profiles/static/img/contact_messagefriend.gif
    [6] => http://x.myspacecdn.com/modules/profiles/static/img/contact_blockuser.gif
    [7] => http://x.myspacecdn.com/modules/profiles/static/img/contact_addtogroupicon.gif
    [8] => http://x.myspacecdn.com/modules/profiles/static/img/contact_rankusericon.gif
)

 

This is based on the assumption that 1) You want ALL the image paths within your lump of code, and 2) all images end with .gif

Otherwise, if you want to be open to more image formats, you can use this pattern instead:

 

#img.+?(https?:.+?\.(?:gif|jpe?g|png))#s

 

This will match images ending in .gif or .jpg or .jpeg or .png

 

Is this what you seek?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.