TFD3 Posted October 21, 2007 Share Posted October 21, 2007 In this script: http://www.alabamaweather.org/scripts/test2.txt I have it set where it looks in the URL and find the <title></title> tags and displays all the data that is in between them. However, the URL that is being read in the script had more than one <title> tags. How can I get the script to display ALL of the info that is in between the title tags? Thanks for your help! Quote Link to comment Share on other sites More sharing options...
TFD3 Posted October 21, 2007 Author Share Posted October 21, 2007 any ideas? Quote Link to comment Share on other sites More sharing options...
derwert Posted October 21, 2007 Share Posted October 21, 2007 There is no problem with preg_match_all, it's your other code <pre> <?php $data = file_get_contents('http://www.spc.noaa.gov/products/spcrss.xml'); preg_match_all('|<title>(.*)</title>|', $data, $headers); print_r ($headers); ?> </pre> Quote Link to comment Share on other sites More sharing options...
TFD3 Posted October 26, 2007 Author Share Posted October 26, 2007 From that code above I get this: Array ( [0] => Array ( [0] => [1] => [2] => [3] => ) [1] => Array ( [0] => Storm Prediction Center Forecast Products [1] => NOAA's National Weather Service [2] => SPC - No watches are valid as of Fri Oct 26 21:07:02 UTC 2007 [3] => SPC MD 2138 ) ) I would like to get just this for example if at all possible: Storm Prediction Center Forecast Products NOAA's National Weather Service SPC - No watches are valid as of Fri Oct 26 21:07:02 UTC 2007 SPC MD 2138 Anyone know what to change/add to the script? Quote Link to comment Share on other sites More sharing options...
effigy Posted October 26, 2007 Share Posted October 26, 2007 You already have it, but it's in an array. You can reassign it entirely: $headers = $headers[1];. P.S. I would use |<title>(.*?)</title>|s. Quote Link to comment Share on other sites More sharing options...
TFD3 Posted October 26, 2007 Author Share Posted October 26, 2007 Im getting this: Array ( [0] => Storm Prediction Center Forecast Products [1] => NOAA's National Weather Service [2] => SPC - No watches are valid as of Fri Oct 26 21:29:01 UTC 2007 [3] => SPC MD 2138 ) Quote Link to comment Share on other sites More sharing options...
derwert Posted October 27, 2007 Share Posted October 27, 2007 Im getting this: Array ( [0] => Storm Prediction Center Forecast Products [1] => NOAA's National Weather Service [2] => SPC - No watches are valid as of Fri Oct 26 21:29:01 UTC 2007 [3] => SPC MD 2138 ) You have to go through the array... Try to take some time and read through the PHP manual <pre><?php $data = file_get_contents('http://www.spc.noaa.gov/products/spcrss.xml'); preg_match_all('|<title>(.*)</title>|U', $data, $headers); $count = count($headers[1]); for ($x = 0; $x <= $count-1; $x++) { echo $headers[1][$x]."\n"; } echo "\n\n OR \n\n"; foreach ($headers[1] as $header){ echo $header."\n"; } echo "\n\n OR \n\n"; $x = 0; while ($x <= $count-1) { echo $headers[1][$x]."\n"; $x++; } echo "\n\n OR \n\n"; echo implode("\n", $headers[1]); ?> </pre> There are plenty different ways to accomplish this.. 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.