Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5974131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:53:58+00:00 2026-05-22T20:53:58+00:00

This script seems to me too long. Is there any way to optimize it?

  • 0

This script seems to me too long. Is there any way to optimize it?

function delteg($string){
$keyp=0;
$out="";
   for ($i=0; $i<strlen($string); $i++) { 
           if ($string[$i]=="<"):
             $keyp=1;
           endif;

           if ($keyp==0):
             $out.=$string[$i];
           endif;

           if ($string[$i]==">"):
             $keyp=0;
           endif;

   }
   $out = substr($out,0,strlen($out));
   return $out;
}

$time_step = array();
$datetime = array();
$G = array();
$HHii = array();
$cloud_cover = array();
$precipitation = array();
$pressure = array();
$temperature = array();
$humidity = array();
$wind_direction = array();
$wind_velocity = array();
$falls = array();
$drops = array();
$n = 0;

$handle = fopen ("http://rp5.ua/xml/257885/en", "r");
while (!feof ($handle)) {
$buffer = fgets($handle, 4096); 

 if (strpos($buffer, "country_id")>0) ($country_id[$n]=delteg($buffer)); 
 if (strpos($buffer, "point_name")>0) ($point_name[$n]=delteg($buffer));
 if (strpos($buffer, "point_name_trim")>0) ($point_name_trim[$n]=delteg($buffer)); 
 if (strpos($buffer, "point_name2")>0) ($point_name2[$n]=delteg($buffer));
 if (strpos($buffer, "point_timestamp")>0) ($point_timestamp[$n]=delteg($buffer)); 
 if (strpos($buffer, "gmt_add")>0) ($gmt_add[$n]=delteg($buffer)); 
 if (strpos($buffer, "point_date")>0) ($point_date[$n]=delteg($buffer));
 if (strpos($buffer, "point_date_time")>0) ($point_date_time[$n]=delteg($buffer)); 
 if (strpos($buffer, "time_step")>0) ($time_step[$n]=delteg($buffer)); 
 if (strpos($buffer, "datetime")>0) ($datetime[$n]=delteg($buffer));
 if (strpos($buffer, "G")>0) ($G[$n]=delteg($buffer)); 
 if (strpos($buffer, "HHii")>0) ($HHii[$n]=delteg($buffer));
 if (strpos($buffer, "cloud_cover")>0) ($cloud_cover[$n]=delteg($buffer)); 
 if (strpos($buffer, "precipitation")>0) ($precipitation[$n]=delteg($buffer));
 if (strpos($buffer, "pressure")>0) ($pressure[$n]=delteg($buffer)); 
 if (strpos($buffer, "temperature")>0) ($temperature[$n]=delteg($buffer));
 if (strpos($buffer, "humidity")>0) ($humidity[$n]=delteg($buffer)); 
 if (strpos($buffer, "wind_direction")>0) ($wind_direction[$n]=delteg($buffer));
 if (strpos($buffer, "wind_velocity")>0) ($wind_velocity[$n]=delteg($buffer)); 
 if (strpos($buffer, "falls")>0) ($falls[$n]=delteg($buffer));
 if (strpos($buffer, "drops")>0) :($drops[$n]=delteg($buffer));
   $n++;
 endif;

}

fclose ($handle);

for ($i=0; $i<$n; $i++) {
     echo $country_id[$i]." - ".$point_name[$i]. " etc.....";

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:53:59+00:00Added an answer on May 22, 2026 at 8:53 pm

    Definitely. You should use an XML parser, like SimpleXML.

    Example:

    $xml = simplexml_load_file("http://rp5.ua/xml/257885/en");
    
    foreach($xml->point as $point) {
        echo 'Point: ', $point->point_name, PHP_EOL;
        foreach($point->timestep as $step) {
            echo "\t Time: ", $step->datetime, PHP_EOL;
        }
    }
    

    There is really no reason to parse XML manually. You save yourself a lot of trouble if you use a parser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made an image upload script using the move_uploaded_file function. This function seems to
I've been thinking about this far too long and haven't gotten any idea, maybe
I've been struggling with this for far too long, and I don't see any
This seems redundant, running perl from a Perl script itself. my $Pref = &*())(*&^%$#@!;
I'm following this tutorial (seems good) for Rails. After I run ruby script/generate scaffold
I have the following code in a shell script. This only seems to work
Well basically I have this script that takes a long time to execute and
This script seems to get hung up when it hits the series of if
It might be that I've been staring at this for too long, and the
This is weird. Only on mobile safari, and since last night this script.... function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.