Re: Array Search Problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



did you read the help for those functions on php.net?

On Wed, Mar 10, 2010 at 4:12 PM, Alice Wei <ajwei@xxxxxxxxxxxxx> wrote:
>
> Hi,
>
>  I have the code as shown in the following that I am trying to create the image of based on the file loaded into the file and additional edits. The problem here appears to be that no matter what value I have in the $distance_to_destination variable, it does not affect any changes on the map. What I am trying to do here is to create a map based on the pre-passed through colors of individual states from another program, but I have to match up the colors based on the values of the correct states.
>
>  I figured that I may have problems with
>
>    $key= array_search($location2,$from); //Find out the position of the index in the array
>
>    $colors_style = ";fill:" . $state_colors[$key];  //Use the index from array_search to apply to the color index
>
> Obviously, it is not applying the colors to the states that I would like other than doing it one by one as the order of what is in the $from variable. Could someone please give me some hints on how I could do the array_search here based on the "value" of the values in the $distance_to_distance and apply the color to the states?
>
> <?php
>
> header("Content-type: image/svg+xml"); //Outputting an SVG
>
> $from = $_GET['from'];
> $state_colors= $_GET['state_colors'];
> $distance_to_destination= $_GET['distance_to_destination'];
>
> $from = explode("-", $from);
> $state_colors= explode("-", $state_colors);
> $change = explode("-",$change);
>
> #Load the Map
> $ourFileName= "USA_Counties_with_FIPS_and_names.svg";
> $fh = fopen($ourFileName, "r") or die("Can't open file");
> $contents = fread($fh,filesize($ourFileName));
> $lines2= file($ourFileName);
>
> foreach ($lines2 as $line_num => $line2) {
>
> $style_line_num = $line_num+3;
> $line2 = trim($line2);
>
>      if(preg_match("/^style/",$line2)) {
>
>       $rest = substr($line2,0,-1);
>
>       for ($j=$line_num;$j<=$style_line_num;$j++){
>         if(preg_match("/inkscape:label/",$lines2[$j])) {
>            $location = explode("=",$lines2[$j]);
>            $location2 = substr($location[1],1,-6);
>
>            if(in_array($location2, $from)) {
>
>             $key= array_search($location2,$from); //Find out the position of the index in the array
>             $colors_style = ";fill:" . $state_colors[$key];  //Use the index from array_search to apply to the color index
>             $rest2 = substr($line2,0,-1). $colors_style . "\"";
>             echo $rest2 . "\n";
>            }
>            else echo $line2 . "\n";
>
>         } //end preg_match inkscape
>     } //end for loop
>   }  //If preg_match style
>
>     else echo $line2 . "\n"; //else if preg_match style
>  } //end for each
>
> fclose($fh);
> ?>
>
> Thanks for your help.
>
> Alice
>
> _________________________________________________________________
> Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
> http://clk.atdmt.com/GBL/go/201469226/direct/01/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux