Jump to content

Godfrey

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Godfrey's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Huh... I was for some reason making that way more complex than needed. Thanks much.
  2. Alright, hopefully my last question for this current project. I've build an array containing other arrays which each hold 5 values. I'm trying to loop through all the arrays in the main array but only pull out one of the values. What I have right now is: echo "<ol>"; for ($rw = 0; $rw < sizeof($serenwilde); $rw++) { echo "<li><b>The row number $rw</b>"; echo "<ul>"; for ($col = 0; $col < 5; $col++) { if (isset($serenwilde[$rw][$col])) { echo "<li>".$serenwilde[$rw][$col]."</li>"; } } echo "</ul>"; echo "</li>"; } echo "</ol>"; Which produces: How can I modify my code so I still loop through all the arrays, but only pull out say value0 from each of them? Thanks again.
  3. I ended up scraping just the names in another way, and the other data in the same way, and that worked. So thanks.
  4. I'm trying to get back into PHP, but I'm running into some trouble. I'm creating a little script that scraps data from a page and then displays it elsewhere. (I'm actually going to insert it into a database, but for now, just trying to display it! There's two pages I'm scraping from. This scrapes the list of players from one web page: $html = file_get_contents("http://www.somesite.com/players.php?search=who"); preg_match_all( '/<td width=\'33\.3333333333\%\'><a href=\'\/players.php\?lookup=.*?\'>(.*?)<\/a>/', $html, $players, PREG_SET_ORDER ); That matches fine. Then for each name I want to scrape another page that has more information about each individual player: foreach ($players as $player) { $html2 = file_get_contents("http://www.somesite.com/players.php?lookup=$player"); preg_match_all( '/<font size=\'\+1\'><strong>.*?<\/font><\/strong>/', $html2, $longName, PREG_SET_ORDER ); preg_match_all( '/Race<\/font><\/td><td><font size=\'\-1\'>.*?<\/font>/', $html2, $race, PREG_SET_ORDER ); preg_match_all( '/Citizenship<\/font><\/td><td><font size=\'\-1\'>.*?<\/font>/', $html2, $citizenship, PREG_SET_ORDER ); preg_match_all( '/Level<\/font><\/td><td><font size=\'\-1\'>.*?<\/font>/', $html2, $level, PREG_SET_ORDER ); echo $longName[0][0]; echo ("<br>"); $rac = implode("", $race[0]); $newrace = substr($rac, 4, -1); echo $newrace; echo ("<br>"); $cit = implode("", $citizenship[0]); $newcit = substr($cit, 11, -1); echo $newcit; echo ("<br>"); $lev = implode("", $level[0]); $newlevel = substr($lev, 5, -1); echo $newlevel; echo ("<br>"); } This does not work. I get Warning: implode() [function.implode]: Invalid arguments passed in /my/path/names.php on line <three implode lines> and I get NO echos except for the break lines. HOWEVER, if I just use this code outside of a loop, i.e. I just do $html2 = file_get_contents("http://www.somesite.com/players.php?lookup=MyPlayerName"); it works perfectly. I'm newb at coding, so I can't even figure out what data it is or is not getting in the iteration, and why it's not displaying/getting it when it's looped through each name as opposed to when it works perfectly when I input a single name in the file_get_contents. Can anyone see errors in how I'm going about this or suggest some checks to put in to help figure out what the heck is going wrong? Thanks much for any help.
×
×
  • 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.