Faster or Simpler Methods To Generate an HTML String using an Array in PHPechoing html tags in phpAdd HTML to...

Reversed Sudoku

Find longest word in a string: are any of these algorithms good?

Accepted offer letter, position changed

Could you please stop shuffling the deck and play already?

Motivation for Zeta Function of an Algebraic Variety

What was the Kree's motivation in Captain Marvel?

How strictly should I take "Candidates must be local"?

How can I get players to stop ignoring or overlooking the plot hooks I'm giving them?

They call me Inspector Morse

Makefile strange variable substitution

An alternative proof of an application of Hahn-Banach

Word for a person who has no opinion about whether god exists

How to write ı (i without dot) character in pgf-pie

When a wind turbine does not produce enough electricity how does the power company compensate for the loss?

Can Mathematica be used to create an Artistic 3D extrusion from a 2D image and wrap a line pattern around it?

Does a warlock using the Darkness/Devil's Sight combo still have advantage on ranged attacks against a target outside the Darkness?

Are all players supposed to be able to see each others' character sheets?

How to draw cubes in a 3 dimensional plane

Are tamper resistant receptacles really safer?

Why would one plane in this picture not have gear down yet?

UART pins to unpowered MCU?

What are actual Tesla M60 models used by AWS?

Accountant/ lawyer will not return my call

Virginia employer terminated employee and wants signing bonus returned



Faster or Simpler Methods To Generate an HTML String using an Array in PHP


echoing html tags in phpAdd HTML to the page using a PHP ClassReview structure of PHP/HTMLScraping HTML using PHPGenerate every unique combination using all elements from arrayPHP function (in WordPress) echoing HTMLHTML Form validation with PHPphp inside html indent stylephp/html template for checkoutGenerate a CSV file from a multidimensional array in php













0












$begingroup$


Problem



Method getQuoteHTML generates an HTML string using an array returned from getQuoteParams method, which works okay. They are methods of a large class, called UpdateStocks.



Would you be so kind and help me to replace them with faster, easier or more efficient methods, if possible?



getQuoteHTML:



    /**
*
* @return a large HTML string of current quote section
*/
public static function getQuoteHTML($a){
$i=UpdateStocks::getQuoteParams();
$bt='<a href="#" class="s18 ro tx-1 b119 r100 t-21 p-2 br-5 mv-3" onclick="J.s({d:this});return false;" title="'.$a["symbol"].' latest quote">💹 Quote: '.date('l, d F Y ⏱ H:i T',microtime(true)).'</a>';
$hs='';
foreach($i as $k=>$p){
$h='';
if(isset($p["id"])&&!empty($a[$p["ky"]])){
if(preg_match('/(^s-*)/i',$p["id"])==1){
$r=rand(20,99);
$h=$h.'<p id="'.$p["id"].'">';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$a[$p["ky"]].'</b>';
$h=$h.'</p>';
$hs=$hs.$h;
}elseif(preg_match('/(^d-*)/i',$p["id"])==1){
$r=rand(20,99);
$h=$h.'<p id="'.$p["id"].'">';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=9.4n',(double)$a[$p["ky"]]).'</b>';
$h=$h.'</p>';
$hs=$hs.$h;
}elseif(preg_match('/(^v-*)/i',$p["id"])==1){
$r=rand(20,99);
$h=$h.'<p id="'.$p["id"].'">';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=*!#4.0n',(double)$a[$p["ky"]]).'</b>';
$h=$h.'</p>';
$hs=$hs.$h;
}elseif(preg_match('/(^t-*)/i',$p["id"])==1){
$r=rand(20,99);
$h=$h.'<p id="'.$p["id"].'">';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.date('l, d F Y ⏱ H:i T (P UTC)',(double)$a[$p["ky"]]/1000).'</b>';
$h=$h.'</p>';
$hs=$hs.$h;
}elseif(preg_match('/(^p-*)/i',$p["id"])==1){
$r=rand(20,99);
$h=$h.'<p id="'.$p["id"].'">';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=*!#4.4n',(double)$a[$p["ky"]]).'%</b>';
$h=$h.'</p>';
$hs=$hs.$h;
}else{
$r=rand(20,99);
$h=$h.'<p id="'.$p["id"].'">';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
$h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$a[$p["ky"]].'%</b>';
$h=$h.'</p>';
$hs=$hs.$h;
}
} // isset
$h='';
}

return '<div class="ro">'.$bt.'<div class="di-0"><div class="p-3">'.$hs.'</div></div></div>';
}


getQuoteParams:



  /**
*
* @return an array of parameters for stock quote from version 1 API at iextrading
*/
public static function getQuoteParams(){
$params=array(
array(
"id"=>"s-sy",
"ky"=>"symbol",
"lb"=>"Symbol",
),
array(
"id"=>"s-cn",
"ky"=>"companyName",
"lb"=>"Company",
),
array(
"id"=>"s-mk",
"ky"=>"primaryExchange",
"lb"=>"Primary Exchange Market",
),
array(
"id"=>"s-st",
"ky"=>"sector",
"lb"=>"Market Sector",
),
array(
"id"=>"d-op",
"ky"=>"open",
"lb"=>"Open Share Price [$]",
),
array(
"id"=>"t-ot",
"ky"=>"openTime",
"lb"=>"Open Time",
),
array(
"id"=>"d-cl",
"ky"=>"close",
"lb"=>"Close Share Price [$]",
),
array(
"id"=>"t-ct",
"ky"=>"closeTime",
"lb"=>"Close Time",
),
array(
"id"=>"d-hi",
"ky"=>"high",
"lb"=>"Current High Share Price [$]",
),
array(
"id"=>"d-lo",
"ky"=>"low",
"lb"=>"Current Low Share Price [$]",
),
array(
"id"=>"d-lp",
"ky"=>"latestPrice",
"lb"=>"Current Latest Share Price [$]",
),
array(
"id"=>"s-ls",
"ky"=>"latestSource",
"lb"=>"Data Source",
),
array(
"id"=>"t-lu",
"ky"=>"latestUpdate",
"lb"=>"Current Latest Update",
),
array(
"id"=>"v-lv",
"ky"=>"latestVolume",
"lb"=>"Current Latest Volume [V]",
),
array(
"id"=>"d-rp",
"ky"=>"iexRealtimePrice",
"lb"=>"Source Near-Real-Time Share Price [$]",
),
array(
"id"=>"v-rs",
"ky"=>"iexRealtimeSize",
"lb"=>"Source Near-Real-Time Size [V]",
),
array(
"id"=>"t-iu",
"ky"=>"iexLastUpdated",
"lb"=>"Source Latest Update",
),
array(
"id"=>"d-dp",
"ky"=>"delayedPrice",
"lb"=>"Delayed Share Price [$]",
),
array(
"id"=>"t-dt",
"ky"=>"delayedPriceTime",
"lb"=>"Delayed Share Price Time",
),
array(
"id"=>"d-ep",
"ky"=>"extendedPrice",
"lb"=>"Extended Share Price [$]",
),
array(
"id"=>"d-ec",
"ky"=>"extendedChange",
"lb"=>"Extended Dollar Change [$]",
),
array(
"id"=>"p-cp",
"ky"=>"extendedChangePercent",
"lb"=>"Extended Percent Change [%]",
),
array(
"id"=>"t-et",
"ky"=>"extendedPriceTime",
"lb"=>"Extended Share Price Time",
),
array(
"id"=>"d-pc",
"ky"=>"previousClose",
"lb"=>"Close Share Price in Previous Session [$]",
),
array(
"id"=>"d-ch",
"ky"=>"change",
"lb"=>"Share Price Change [$]",
),
array(
"id"=>"p-pr",
"ky"=>"changePercent",
"lb"=>"Share Price Change [%]",
),
array(
"id"=>"p-mp",
"ky"=>"iexMarketPercent",
"lb"=>"Source Market Share [%]",
),
array(
"id"=>"v-vl",
"ky"=>"iexVolume",
"lb"=>"Source Volume [V]",
),
array(
"id"=>"v-av",
"ky"=>"avgTotalVolume",
"lb"=>"Average Total Volume [V]",
),
array(
"id"=>"d-bp",
"ky"=>"iexBidPrice",
"lb"=>"Source Bid Price [$]",
),
array(
"id"=>"v-bs",
"ky"=>"iexBidSize",
"lb"=>"Source Bid Size [V]",
),
array(
"id"=>"d-ap",
"ky"=>"iexAskPrice",
"lb"=>"Source Ask Price [$]",
),
array(
"id"=>"v-as",
"ky"=>"iexAskSize",
"lb"=>"Source Ask Size [V]",
),
array(
"id"=>"d-cc",
"ky"=>"marketCap",
"lb"=>"Company Market Cap [$]",
),
array(
"id"=>"s-pe",
"ky"=>"peRatio",
"lb"=>"PE Ratio",
),
array(
"id"=>"d-wh",
"ky"=>"week52High",
"lb"=>"52-Week High [$]",
),
array(
"id"=>"d-wl",
"ky"=>"week52Low",
"lb"=>"52-Week Low [$]",
),
array(
"id"=>"p-yt",
"ky"=>"ytdChange",
"lb"=>"YTD Change",
),
);
return $params;
}


Part of HTML Output:



View










share|improve this question











$endgroup$

















    0












    $begingroup$


    Problem



    Method getQuoteHTML generates an HTML string using an array returned from getQuoteParams method, which works okay. They are methods of a large class, called UpdateStocks.



    Would you be so kind and help me to replace them with faster, easier or more efficient methods, if possible?



    getQuoteHTML:



        /**
    *
    * @return a large HTML string of current quote section
    */
    public static function getQuoteHTML($a){
    $i=UpdateStocks::getQuoteParams();
    $bt='<a href="#" class="s18 ro tx-1 b119 r100 t-21 p-2 br-5 mv-3" onclick="J.s({d:this});return false;" title="'.$a["symbol"].' latest quote">💹 Quote: '.date('l, d F Y ⏱ H:i T',microtime(true)).'</a>';
    $hs='';
    foreach($i as $k=>$p){
    $h='';
    if(isset($p["id"])&&!empty($a[$p["ky"]])){
    if(preg_match('/(^s-*)/i',$p["id"])==1){
    $r=rand(20,99);
    $h=$h.'<p id="'.$p["id"].'">';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$a[$p["ky"]].'</b>';
    $h=$h.'</p>';
    $hs=$hs.$h;
    }elseif(preg_match('/(^d-*)/i',$p["id"])==1){
    $r=rand(20,99);
    $h=$h.'<p id="'.$p["id"].'">';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=9.4n',(double)$a[$p["ky"]]).'</b>';
    $h=$h.'</p>';
    $hs=$hs.$h;
    }elseif(preg_match('/(^v-*)/i',$p["id"])==1){
    $r=rand(20,99);
    $h=$h.'<p id="'.$p["id"].'">';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=*!#4.0n',(double)$a[$p["ky"]]).'</b>';
    $h=$h.'</p>';
    $hs=$hs.$h;
    }elseif(preg_match('/(^t-*)/i',$p["id"])==1){
    $r=rand(20,99);
    $h=$h.'<p id="'.$p["id"].'">';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.date('l, d F Y ⏱ H:i T (P UTC)',(double)$a[$p["ky"]]/1000).'</b>';
    $h=$h.'</p>';
    $hs=$hs.$h;
    }elseif(preg_match('/(^p-*)/i',$p["id"])==1){
    $r=rand(20,99);
    $h=$h.'<p id="'.$p["id"].'">';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=*!#4.4n',(double)$a[$p["ky"]]).'%</b>';
    $h=$h.'</p>';
    $hs=$hs.$h;
    }else{
    $r=rand(20,99);
    $h=$h.'<p id="'.$p["id"].'">';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
    $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$a[$p["ky"]].'%</b>';
    $h=$h.'</p>';
    $hs=$hs.$h;
    }
    } // isset
    $h='';
    }

    return '<div class="ro">'.$bt.'<div class="di-0"><div class="p-3">'.$hs.'</div></div></div>';
    }


    getQuoteParams:



      /**
    *
    * @return an array of parameters for stock quote from version 1 API at iextrading
    */
    public static function getQuoteParams(){
    $params=array(
    array(
    "id"=>"s-sy",
    "ky"=>"symbol",
    "lb"=>"Symbol",
    ),
    array(
    "id"=>"s-cn",
    "ky"=>"companyName",
    "lb"=>"Company",
    ),
    array(
    "id"=>"s-mk",
    "ky"=>"primaryExchange",
    "lb"=>"Primary Exchange Market",
    ),
    array(
    "id"=>"s-st",
    "ky"=>"sector",
    "lb"=>"Market Sector",
    ),
    array(
    "id"=>"d-op",
    "ky"=>"open",
    "lb"=>"Open Share Price [$]",
    ),
    array(
    "id"=>"t-ot",
    "ky"=>"openTime",
    "lb"=>"Open Time",
    ),
    array(
    "id"=>"d-cl",
    "ky"=>"close",
    "lb"=>"Close Share Price [$]",
    ),
    array(
    "id"=>"t-ct",
    "ky"=>"closeTime",
    "lb"=>"Close Time",
    ),
    array(
    "id"=>"d-hi",
    "ky"=>"high",
    "lb"=>"Current High Share Price [$]",
    ),
    array(
    "id"=>"d-lo",
    "ky"=>"low",
    "lb"=>"Current Low Share Price [$]",
    ),
    array(
    "id"=>"d-lp",
    "ky"=>"latestPrice",
    "lb"=>"Current Latest Share Price [$]",
    ),
    array(
    "id"=>"s-ls",
    "ky"=>"latestSource",
    "lb"=>"Data Source",
    ),
    array(
    "id"=>"t-lu",
    "ky"=>"latestUpdate",
    "lb"=>"Current Latest Update",
    ),
    array(
    "id"=>"v-lv",
    "ky"=>"latestVolume",
    "lb"=>"Current Latest Volume [V]",
    ),
    array(
    "id"=>"d-rp",
    "ky"=>"iexRealtimePrice",
    "lb"=>"Source Near-Real-Time Share Price [$]",
    ),
    array(
    "id"=>"v-rs",
    "ky"=>"iexRealtimeSize",
    "lb"=>"Source Near-Real-Time Size [V]",
    ),
    array(
    "id"=>"t-iu",
    "ky"=>"iexLastUpdated",
    "lb"=>"Source Latest Update",
    ),
    array(
    "id"=>"d-dp",
    "ky"=>"delayedPrice",
    "lb"=>"Delayed Share Price [$]",
    ),
    array(
    "id"=>"t-dt",
    "ky"=>"delayedPriceTime",
    "lb"=>"Delayed Share Price Time",
    ),
    array(
    "id"=>"d-ep",
    "ky"=>"extendedPrice",
    "lb"=>"Extended Share Price [$]",
    ),
    array(
    "id"=>"d-ec",
    "ky"=>"extendedChange",
    "lb"=>"Extended Dollar Change [$]",
    ),
    array(
    "id"=>"p-cp",
    "ky"=>"extendedChangePercent",
    "lb"=>"Extended Percent Change [%]",
    ),
    array(
    "id"=>"t-et",
    "ky"=>"extendedPriceTime",
    "lb"=>"Extended Share Price Time",
    ),
    array(
    "id"=>"d-pc",
    "ky"=>"previousClose",
    "lb"=>"Close Share Price in Previous Session [$]",
    ),
    array(
    "id"=>"d-ch",
    "ky"=>"change",
    "lb"=>"Share Price Change [$]",
    ),
    array(
    "id"=>"p-pr",
    "ky"=>"changePercent",
    "lb"=>"Share Price Change [%]",
    ),
    array(
    "id"=>"p-mp",
    "ky"=>"iexMarketPercent",
    "lb"=>"Source Market Share [%]",
    ),
    array(
    "id"=>"v-vl",
    "ky"=>"iexVolume",
    "lb"=>"Source Volume [V]",
    ),
    array(
    "id"=>"v-av",
    "ky"=>"avgTotalVolume",
    "lb"=>"Average Total Volume [V]",
    ),
    array(
    "id"=>"d-bp",
    "ky"=>"iexBidPrice",
    "lb"=>"Source Bid Price [$]",
    ),
    array(
    "id"=>"v-bs",
    "ky"=>"iexBidSize",
    "lb"=>"Source Bid Size [V]",
    ),
    array(
    "id"=>"d-ap",
    "ky"=>"iexAskPrice",
    "lb"=>"Source Ask Price [$]",
    ),
    array(
    "id"=>"v-as",
    "ky"=>"iexAskSize",
    "lb"=>"Source Ask Size [V]",
    ),
    array(
    "id"=>"d-cc",
    "ky"=>"marketCap",
    "lb"=>"Company Market Cap [$]",
    ),
    array(
    "id"=>"s-pe",
    "ky"=>"peRatio",
    "lb"=>"PE Ratio",
    ),
    array(
    "id"=>"d-wh",
    "ky"=>"week52High",
    "lb"=>"52-Week High [$]",
    ),
    array(
    "id"=>"d-wl",
    "ky"=>"week52Low",
    "lb"=>"52-Week Low [$]",
    ),
    array(
    "id"=>"p-yt",
    "ky"=>"ytdChange",
    "lb"=>"YTD Change",
    ),
    );
    return $params;
    }


    Part of HTML Output:



    View










    share|improve this question











    $endgroup$















      0












      0








      0





      $begingroup$


      Problem



      Method getQuoteHTML generates an HTML string using an array returned from getQuoteParams method, which works okay. They are methods of a large class, called UpdateStocks.



      Would you be so kind and help me to replace them with faster, easier or more efficient methods, if possible?



      getQuoteHTML:



          /**
      *
      * @return a large HTML string of current quote section
      */
      public static function getQuoteHTML($a){
      $i=UpdateStocks::getQuoteParams();
      $bt='<a href="#" class="s18 ro tx-1 b119 r100 t-21 p-2 br-5 mv-3" onclick="J.s({d:this});return false;" title="'.$a["symbol"].' latest quote">💹 Quote: '.date('l, d F Y ⏱ H:i T',microtime(true)).'</a>';
      $hs='';
      foreach($i as $k=>$p){
      $h='';
      if(isset($p["id"])&&!empty($a[$p["ky"]])){
      if(preg_match('/(^s-*)/i',$p["id"])==1){
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$a[$p["ky"]].'</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }elseif(preg_match('/(^d-*)/i',$p["id"])==1){
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=9.4n',(double)$a[$p["ky"]]).'</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }elseif(preg_match('/(^v-*)/i',$p["id"])==1){
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=*!#4.0n',(double)$a[$p["ky"]]).'</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }elseif(preg_match('/(^t-*)/i',$p["id"])==1){
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.date('l, d F Y ⏱ H:i T (P UTC)',(double)$a[$p["ky"]]/1000).'</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }elseif(preg_match('/(^p-*)/i',$p["id"])==1){
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=*!#4.4n',(double)$a[$p["ky"]]).'%</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }else{
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$a[$p["ky"]].'%</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }
      } // isset
      $h='';
      }

      return '<div class="ro">'.$bt.'<div class="di-0"><div class="p-3">'.$hs.'</div></div></div>';
      }


      getQuoteParams:



        /**
      *
      * @return an array of parameters for stock quote from version 1 API at iextrading
      */
      public static function getQuoteParams(){
      $params=array(
      array(
      "id"=>"s-sy",
      "ky"=>"symbol",
      "lb"=>"Symbol",
      ),
      array(
      "id"=>"s-cn",
      "ky"=>"companyName",
      "lb"=>"Company",
      ),
      array(
      "id"=>"s-mk",
      "ky"=>"primaryExchange",
      "lb"=>"Primary Exchange Market",
      ),
      array(
      "id"=>"s-st",
      "ky"=>"sector",
      "lb"=>"Market Sector",
      ),
      array(
      "id"=>"d-op",
      "ky"=>"open",
      "lb"=>"Open Share Price [$]",
      ),
      array(
      "id"=>"t-ot",
      "ky"=>"openTime",
      "lb"=>"Open Time",
      ),
      array(
      "id"=>"d-cl",
      "ky"=>"close",
      "lb"=>"Close Share Price [$]",
      ),
      array(
      "id"=>"t-ct",
      "ky"=>"closeTime",
      "lb"=>"Close Time",
      ),
      array(
      "id"=>"d-hi",
      "ky"=>"high",
      "lb"=>"Current High Share Price [$]",
      ),
      array(
      "id"=>"d-lo",
      "ky"=>"low",
      "lb"=>"Current Low Share Price [$]",
      ),
      array(
      "id"=>"d-lp",
      "ky"=>"latestPrice",
      "lb"=>"Current Latest Share Price [$]",
      ),
      array(
      "id"=>"s-ls",
      "ky"=>"latestSource",
      "lb"=>"Data Source",
      ),
      array(
      "id"=>"t-lu",
      "ky"=>"latestUpdate",
      "lb"=>"Current Latest Update",
      ),
      array(
      "id"=>"v-lv",
      "ky"=>"latestVolume",
      "lb"=>"Current Latest Volume [V]",
      ),
      array(
      "id"=>"d-rp",
      "ky"=>"iexRealtimePrice",
      "lb"=>"Source Near-Real-Time Share Price [$]",
      ),
      array(
      "id"=>"v-rs",
      "ky"=>"iexRealtimeSize",
      "lb"=>"Source Near-Real-Time Size [V]",
      ),
      array(
      "id"=>"t-iu",
      "ky"=>"iexLastUpdated",
      "lb"=>"Source Latest Update",
      ),
      array(
      "id"=>"d-dp",
      "ky"=>"delayedPrice",
      "lb"=>"Delayed Share Price [$]",
      ),
      array(
      "id"=>"t-dt",
      "ky"=>"delayedPriceTime",
      "lb"=>"Delayed Share Price Time",
      ),
      array(
      "id"=>"d-ep",
      "ky"=>"extendedPrice",
      "lb"=>"Extended Share Price [$]",
      ),
      array(
      "id"=>"d-ec",
      "ky"=>"extendedChange",
      "lb"=>"Extended Dollar Change [$]",
      ),
      array(
      "id"=>"p-cp",
      "ky"=>"extendedChangePercent",
      "lb"=>"Extended Percent Change [%]",
      ),
      array(
      "id"=>"t-et",
      "ky"=>"extendedPriceTime",
      "lb"=>"Extended Share Price Time",
      ),
      array(
      "id"=>"d-pc",
      "ky"=>"previousClose",
      "lb"=>"Close Share Price in Previous Session [$]",
      ),
      array(
      "id"=>"d-ch",
      "ky"=>"change",
      "lb"=>"Share Price Change [$]",
      ),
      array(
      "id"=>"p-pr",
      "ky"=>"changePercent",
      "lb"=>"Share Price Change [%]",
      ),
      array(
      "id"=>"p-mp",
      "ky"=>"iexMarketPercent",
      "lb"=>"Source Market Share [%]",
      ),
      array(
      "id"=>"v-vl",
      "ky"=>"iexVolume",
      "lb"=>"Source Volume [V]",
      ),
      array(
      "id"=>"v-av",
      "ky"=>"avgTotalVolume",
      "lb"=>"Average Total Volume [V]",
      ),
      array(
      "id"=>"d-bp",
      "ky"=>"iexBidPrice",
      "lb"=>"Source Bid Price [$]",
      ),
      array(
      "id"=>"v-bs",
      "ky"=>"iexBidSize",
      "lb"=>"Source Bid Size [V]",
      ),
      array(
      "id"=>"d-ap",
      "ky"=>"iexAskPrice",
      "lb"=>"Source Ask Price [$]",
      ),
      array(
      "id"=>"v-as",
      "ky"=>"iexAskSize",
      "lb"=>"Source Ask Size [V]",
      ),
      array(
      "id"=>"d-cc",
      "ky"=>"marketCap",
      "lb"=>"Company Market Cap [$]",
      ),
      array(
      "id"=>"s-pe",
      "ky"=>"peRatio",
      "lb"=>"PE Ratio",
      ),
      array(
      "id"=>"d-wh",
      "ky"=>"week52High",
      "lb"=>"52-Week High [$]",
      ),
      array(
      "id"=>"d-wl",
      "ky"=>"week52Low",
      "lb"=>"52-Week Low [$]",
      ),
      array(
      "id"=>"p-yt",
      "ky"=>"ytdChange",
      "lb"=>"YTD Change",
      ),
      );
      return $params;
      }


      Part of HTML Output:



      View










      share|improve this question











      $endgroup$




      Problem



      Method getQuoteHTML generates an HTML string using an array returned from getQuoteParams method, which works okay. They are methods of a large class, called UpdateStocks.



      Would you be so kind and help me to replace them with faster, easier or more efficient methods, if possible?



      getQuoteHTML:



          /**
      *
      * @return a large HTML string of current quote section
      */
      public static function getQuoteHTML($a){
      $i=UpdateStocks::getQuoteParams();
      $bt='<a href="#" class="s18 ro tx-1 b119 r100 t-21 p-2 br-5 mv-3" onclick="J.s({d:this});return false;" title="'.$a["symbol"].' latest quote">💹 Quote: '.date('l, d F Y ⏱ H:i T',microtime(true)).'</a>';
      $hs='';
      foreach($i as $k=>$p){
      $h='';
      if(isset($p["id"])&&!empty($a[$p["ky"]])){
      if(preg_match('/(^s-*)/i',$p["id"])==1){
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$a[$p["ky"]].'</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }elseif(preg_match('/(^d-*)/i',$p["id"])==1){
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=9.4n',(double)$a[$p["ky"]]).'</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }elseif(preg_match('/(^v-*)/i',$p["id"])==1){
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=*!#4.0n',(double)$a[$p["ky"]]).'</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }elseif(preg_match('/(^t-*)/i',$p["id"])==1){
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.date('l, d F Y ⏱ H:i T (P UTC)',(double)$a[$p["ky"]]/1000).'</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }elseif(preg_match('/(^p-*)/i',$p["id"])==1){
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.money_format('%=*!#4.4n',(double)$a[$p["ky"]]).'%</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }else{
      $r=rand(20,99);
      $h=$h.'<p id="'.$p["id"].'">';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$p["lb"].'</b>: ';
      $h=$h.'<b class="di-1 t-21 m-1 br-3 p-2 b119 r1'.$r.'">'.$a[$p["ky"]].'%</b>';
      $h=$h.'</p>';
      $hs=$hs.$h;
      }
      } // isset
      $h='';
      }

      return '<div class="ro">'.$bt.'<div class="di-0"><div class="p-3">'.$hs.'</div></div></div>';
      }


      getQuoteParams:



        /**
      *
      * @return an array of parameters for stock quote from version 1 API at iextrading
      */
      public static function getQuoteParams(){
      $params=array(
      array(
      "id"=>"s-sy",
      "ky"=>"symbol",
      "lb"=>"Symbol",
      ),
      array(
      "id"=>"s-cn",
      "ky"=>"companyName",
      "lb"=>"Company",
      ),
      array(
      "id"=>"s-mk",
      "ky"=>"primaryExchange",
      "lb"=>"Primary Exchange Market",
      ),
      array(
      "id"=>"s-st",
      "ky"=>"sector",
      "lb"=>"Market Sector",
      ),
      array(
      "id"=>"d-op",
      "ky"=>"open",
      "lb"=>"Open Share Price [$]",
      ),
      array(
      "id"=>"t-ot",
      "ky"=>"openTime",
      "lb"=>"Open Time",
      ),
      array(
      "id"=>"d-cl",
      "ky"=>"close",
      "lb"=>"Close Share Price [$]",
      ),
      array(
      "id"=>"t-ct",
      "ky"=>"closeTime",
      "lb"=>"Close Time",
      ),
      array(
      "id"=>"d-hi",
      "ky"=>"high",
      "lb"=>"Current High Share Price [$]",
      ),
      array(
      "id"=>"d-lo",
      "ky"=>"low",
      "lb"=>"Current Low Share Price [$]",
      ),
      array(
      "id"=>"d-lp",
      "ky"=>"latestPrice",
      "lb"=>"Current Latest Share Price [$]",
      ),
      array(
      "id"=>"s-ls",
      "ky"=>"latestSource",
      "lb"=>"Data Source",
      ),
      array(
      "id"=>"t-lu",
      "ky"=>"latestUpdate",
      "lb"=>"Current Latest Update",
      ),
      array(
      "id"=>"v-lv",
      "ky"=>"latestVolume",
      "lb"=>"Current Latest Volume [V]",
      ),
      array(
      "id"=>"d-rp",
      "ky"=>"iexRealtimePrice",
      "lb"=>"Source Near-Real-Time Share Price [$]",
      ),
      array(
      "id"=>"v-rs",
      "ky"=>"iexRealtimeSize",
      "lb"=>"Source Near-Real-Time Size [V]",
      ),
      array(
      "id"=>"t-iu",
      "ky"=>"iexLastUpdated",
      "lb"=>"Source Latest Update",
      ),
      array(
      "id"=>"d-dp",
      "ky"=>"delayedPrice",
      "lb"=>"Delayed Share Price [$]",
      ),
      array(
      "id"=>"t-dt",
      "ky"=>"delayedPriceTime",
      "lb"=>"Delayed Share Price Time",
      ),
      array(
      "id"=>"d-ep",
      "ky"=>"extendedPrice",
      "lb"=>"Extended Share Price [$]",
      ),
      array(
      "id"=>"d-ec",
      "ky"=>"extendedChange",
      "lb"=>"Extended Dollar Change [$]",
      ),
      array(
      "id"=>"p-cp",
      "ky"=>"extendedChangePercent",
      "lb"=>"Extended Percent Change [%]",
      ),
      array(
      "id"=>"t-et",
      "ky"=>"extendedPriceTime",
      "lb"=>"Extended Share Price Time",
      ),
      array(
      "id"=>"d-pc",
      "ky"=>"previousClose",
      "lb"=>"Close Share Price in Previous Session [$]",
      ),
      array(
      "id"=>"d-ch",
      "ky"=>"change",
      "lb"=>"Share Price Change [$]",
      ),
      array(
      "id"=>"p-pr",
      "ky"=>"changePercent",
      "lb"=>"Share Price Change [%]",
      ),
      array(
      "id"=>"p-mp",
      "ky"=>"iexMarketPercent",
      "lb"=>"Source Market Share [%]",
      ),
      array(
      "id"=>"v-vl",
      "ky"=>"iexVolume",
      "lb"=>"Source Volume [V]",
      ),
      array(
      "id"=>"v-av",
      "ky"=>"avgTotalVolume",
      "lb"=>"Average Total Volume [V]",
      ),
      array(
      "id"=>"d-bp",
      "ky"=>"iexBidPrice",
      "lb"=>"Source Bid Price [$]",
      ),
      array(
      "id"=>"v-bs",
      "ky"=>"iexBidSize",
      "lb"=>"Source Bid Size [V]",
      ),
      array(
      "id"=>"d-ap",
      "ky"=>"iexAskPrice",
      "lb"=>"Source Ask Price [$]",
      ),
      array(
      "id"=>"v-as",
      "ky"=>"iexAskSize",
      "lb"=>"Source Ask Size [V]",
      ),
      array(
      "id"=>"d-cc",
      "ky"=>"marketCap",
      "lb"=>"Company Market Cap [$]",
      ),
      array(
      "id"=>"s-pe",
      "ky"=>"peRatio",
      "lb"=>"PE Ratio",
      ),
      array(
      "id"=>"d-wh",
      "ky"=>"week52High",
      "lb"=>"52-Week High [$]",
      ),
      array(
      "id"=>"d-wl",
      "ky"=>"week52Low",
      "lb"=>"52-Week Low [$]",
      ),
      array(
      "id"=>"p-yt",
      "ky"=>"ytdChange",
      "lb"=>"YTD Change",
      ),
      );
      return $params;
      }


      Part of HTML Output:



      View







      beginner php






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 6 mins ago







      Emma

















      asked 31 mins ago









      EmmaEmma

      15912




      15912






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215232%2ffaster-or-simpler-methods-to-generate-an-html-string-using-an-array-in-php%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215232%2ffaster-or-simpler-methods-to-generate-an-html-string-using-an-array-in-php%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Fairchild Swearingen Metro Inhaltsverzeichnis Geschichte | Innenausstattung | Nutzung | Zwischenfälle...

          Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...

          Marineschifffahrtleitung Inhaltsverzeichnis Geschichte | Heutige Organisation der NATO | Nationale und...