Jump to content

preg_match_all question??


TFD3

Recommended Posts

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
)

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.