silver8fox2 Posted February 22, 2007 Share Posted February 22, 2007 I'm trying to load someone's myspace.com into a string, and pull out specific parts of the html text. It would then seach the string ($html) and pick out the first value $name which would be <span class="nametext">NameHere</span>... and so forth. I then will take the values and place it on a banner for my own personal site... I've tried for the past few hours searching but can't come up with the right words. It's kinda like forum sigs in which they take values from a site and place it in a image. Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted February 22, 2007 Share Posted February 22, 2007 Can't remember where I got these functions from and I'm not using them anymore, but I think that they are on the lines that you want : <?php function loadTemplate($file) { global $template; $strfile = $file; if (!file_exists($strfile)) print"Loading template failed!"; $thisfile = file($strfile); while(list($line,$value) = each($thisfile)) { $value = ereg_replace("(\r|\n)","",$value); $template .= "$value\r\n"; } return $template; } function insertTempData($file, $recordset_array) { global $template; $this->loadTemplate($file); foreach ($recordset_array as $key => $value) { $template = str_replace("id='" . $key . "' value=''", "id='" . $key . "' value='" . $value . "'", $template); } return $template; } ?> So what you need to do is pass your file to function loadTemplate($file), That will turn your file into one big long string called $template. Then create an array of constants you want to change, then pass them to function insertTempData($file, $recordset_array). Then do what you want with $template. Hope that helps Quote Link to comment Share on other sites More sharing options...
silver8fox2 Posted February 22, 2007 Author Share Posted February 22, 2007 hmm maybe I'm not as good as i thought I was lol. The URL will be like "http://www.myspace.com/soldierboy2" so to get the source of it I'd put that URL at file or? ... lol i feel so n00b right now. Quote Link to comment Share on other sites More sharing options...
skali Posted February 22, 2007 Share Posted February 22, 2007 $handle = fopen("http://www.website.com/page.html", "r"); This will privide you a file handle to the webpage. But you need to have 'allow_url_fopen' enabled in php.ini. Quote Link to comment Share on other sites More sharing options...
silver8fox2 Posted February 22, 2007 Author Share Posted February 22, 2007 and you can tell if its not if you get "Resource id #1" ? Quote Link to comment Share on other sites More sharing options...
silver8fox2 Posted February 22, 2007 Author Share Posted February 22, 2007 On of my friends back in the day did this, i noticed its slow though but kinda works lol. Prints out: Username: Mark Ryan Age: 20 years old Gender: Male Friends: 111 <?php ### Class ### class sig{ function parse($start, $end, $string, $is_url = false){ if($is_url == true){ $string = file_get_contents($string); } $starting = explode($start, $string); $ending = explode($end, $starting[1]); return $ending[0]; } function InStr($string, $find){ $i = 0; while(strlen($string)>=$i){ unset($substring); $substring = substr($string, $i, strlen($find)); if($substring == $find){ return true; } $i++; } return false; } } ### /Class ### $Sig = new Sig; ### /Get Data ### $id="144816244"; // Gets HTML Source $info = file_get_contents("http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=$id"); //Gather String Text $username = ($Sig->parse("<meta name=\"description\" content=\"MySpace Profile - ", ",", $info)); $age = ($Sig->parse("$usernam,", ",", $info)); $gender = ($Sig->parse("$age,", ",", $info)); $friends = ($Sig->parse("<span class=\"redbtext\">", "<", $info)); //Displays print "<b>Username:</b> $username<br>"; print "<b>Age:</b> $age<br>"; print "<b>Gender:</b> $gender<br>"; print "<b>Friends:</b> $friends<br>"; ?> Just if I could remeber how to do a string and make an array out of this "<meta name="description" content="MySpace Profile - Mark Ryan, 20 years old, Male, CITY, STATE, US," Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted February 23, 2007 Share Posted February 23, 2007 str_replace($CONSTANT, 'replace text', $string); Is what you want for that. So if you combine mine and skali's post then all you need to do is set up a assosiative array of the $CONSTANTS you want to change and maybe edit the str_replace() in the first post if your feeling brave. Don't worry about being a newb either, u gotta start somewhere. I'm no programmer, by a long shot and I've been playing with php 4 6mnts now and am feeling loads more confident now, keep it up Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.