This is a discussion on str_replace stuff within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi all! I'm trying to grab content from my myspace profile with php and fopen. I just want the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi all!
I'm trying to grab content from my myspace profile with php and fopen. I just want the url of my friends profile and the url of their myspace thumbnail so i can load them into flash as a variable. example string output desired: &friend1=http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=495 8197&image1=http://myspace-668.vo.llnwd.net/00102/86/66/102536668_s.jpg so far my progress: http://serverspeed.com/grabmyspace.php this is the code I have so far: <?php $URL = 'http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=441 6517'; // my profile $Start = ' <table width="435" border="0" cellspacing="0" cellpadding="5" align="center">'; $GrabEnd = ' </table>'; $file = fopen("$URL", "r"); $r = file_get_contents($URL); $stuff = eregi("$Start(.*)$GrabEnd", $r, $content); fclose($file); $content = str_replace('<tr>', '', $content); $content = str_replace('<td bgcolor="FFFFFF" align="center" valign="top" width="1">', '', $content); $content = str_replace('<table border="0" cellspacing="0" align="center">', '', $content); $content = str_replace('<td bgcolor="FFFFFF" align="center" valign="top" width="107" style="word-wrap:break-word">', '', $content); $content = str_replace('<table border="0" cellspacing="0" align="center">', '', $content); $content = str_replace(' <a href="', '&link1=', $content); $content = str_replace('</a> ', '', $content); $content = str_replace('</td>', '', $content); $content = str_replace('</tr>', '', $content); $content = str_replace('<td bgcolor="FFFFFF" align="center" valign="top" width="25%"><a href="', '', $content); $content = str_replace('<td bgcolor="FFFFFF" align="center" valign="top" width="25%"><a href="http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=', '', $content); $content = str_replace('<img src="', '&img1=', $content); $content = str_replace('"></a><br>', '', $content); $content = str_replace('<DIV style="width:80px;height:20px;" ID="', '', $content); $content = str_replace('</div>', '', $content); $content = str_replace('</table>', '', $content); echo $content[1]; ?> I appreciate any help on this. I'm getting better at programming but I still get in over my head from time to time. |
|
|||
|
Michael wrote:
> I appreciate any help on this. I'm getting better at programming but > I still get in over my head from time to time. > Remember that less = more; to get all thumbnail links, simply do: $base = 'http://profile.myspace.com'; $path = '/index.cfm?fuseaction=user.viewprofile&friendid=441 6517'; $pattern = '|(http://myspace-\d+.vo.llnwd.net/[\d/]+_s.jpg)|'; $contents = file_get_contents("$base$path"); preg_match_all($pattern, $contents, $matches); print_r($matches); JW |