yujikaido Posted April 16, 2010 Share Posted April 16, 2010 Could anyone please tell what I am doing wrong with my code? I just get a blank page when I echo output and run it on xamplite. Thanks <? $url = "http://www.cs.iusb.edu/people/faculty.html"; $input = @file_get_contents($url) or die('Could not access file: $url'); $pat = "/id=\table1\" .+\<tbody\>(.+)\<\/tbody\>/s"; preg_match($pat,$input,$outp); echo $outp[1]; ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 Don't use @ if you're testing it. That'll suppress any errors should there be any. The regexp is a bit off. Without some HTML sample, this is the best I can do: $pat = "/id=['"]?table1['"]?.+?<tbody>(.+)?<\/tbody>/"; Quote Link to comment Share on other sites More sharing options...
yujikaido Posted April 16, 2010 Author Share Posted April 16, 2010 Hey thanks for the reply. OK I took out the @. and I tested that line of code but got the same result. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 Can you show me what you're trying to match? Quote Link to comment Share on other sites More sharing options...
yujikaido Posted April 16, 2010 Author Share Posted April 16, 2010 Ok I got it to output the html table I wanted but it lost its table format. this is what I want my end result to look like at this address http://www.cs.iusb.edu/~rbatzing/a340/faculty.php so I want to grab the first table "table1" in the body. Thanks <? $url = "http://www.cs.iusb.edu/people/faculty.html"; $input = file_get_contents($url) or die('Could not access file: $url'); if (preg_match("/id=\"table1\" .+?\<tbody\>(.+?)\<\/tbody\>/s",$input,$outp)); echo $outp[1]; ?> Quote Link to comment Share on other sites More sharing options...
yujikaido Posted April 16, 2010 Author Share Posted April 16, 2010 I now got it to pull the table correctly now I somehow have to change the table color and instead of the table being horizonal it has to be vertically stacked with faculty on top Ass. faculty in the middle and staff on the bottom. Does anybody have any idea how I might go about this? Thanks Quote Link to comment Share on other sites More sharing options...
teamatomic Posted April 16, 2010 Share Posted April 16, 2010 preg_match_all("/(<ul.*>)(\w.*)(<\/ul>)/isxmU",$file,$matches); What you want is $matches[0][0-3], arrange as you want. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
yujikaido Posted April 17, 2010 Author Share Posted April 17, 2010 Thanks for the reply and the help. I tried the line but i get: Warning: preg_match_all() expects parameter 2 to be string, array given in /Applications/XAMPP/xamppfiles/htdocs/falculty.php on line 5" when I run it. any suggestions ? <? $url = "http://www.cs.iusb.edu/people/faculty.html"; //set the web address to an array $input = file_get_contents($url) or die('Could not access file: $url'); // input get set to grab the contents of the page or else displays msg. if (preg_match("/<table id=\"table1\" .*?\<tbody\>(.*?)\<\/tbody\>/s",$input,$outp));// preg match first sets the expression to grap table1 and then processing it with $input array and sets the result to $outp array preg_match_all("/(<ul.*>)(\w.*)(<\/ul>)/isxmU",$outp,$matches); echo $matches[0];// ouputs the completed table echo $matches[1];// ouputs the completed table echo $matches[2];// ouputs the completed table ?> 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.