mardi 6 novembre 2018

Converting an abbreviation found in multiple strings to the full word - PHP

I am trying to manipulate a multiple strings in PHP. I am extracting array data using foreach loops and if statements. Some of the array data is stored as abbreviations. I want to convert these abbreviations to the full word. One example is the abbreviation pwr which stands for power. The abbreviation can be found in a variety of different contexts. Below I will attach my PHP code followed by its respective output where you can see the variety of strings the pwr abbreviation can be found in.

PHP:

<?php

foreach ($finaltitle as $titlenumber => $titlename){
 foreach ($techData as $tsnumber => $tsname){
  if ($tsnumber == $titlenumber){
    if(empty($tsname) or $tsname === '- TBD -') continue;

    $finaltsdata = "<b>".$titlename." (".$tsnumber.") "."</b>: ".strtolower($tsname)."<br>";
    echo $finaltsdata;
  }
 }
}

?>

Output:

Suspension Type - Front (105) : 4-link,
Suspension Type - Rear (106) : trapezoidal link,
Suspension Type - Front (Cont.) (107) : pwr-adjustable sport
Suspension Type - Rear (Cont.) (108) : pwr-adjustable sport
Front Tire Size (140) : p235/40yr18
Rear Tire Size (141) : p235/40yr18
Spare Tire Size (142) : p235/40yr18
Front Wheel Size (156) : 18 x 8.0
Rear Wheel Size (157) : 18 x 8.0
Spare Wheel Size (158) : 18 x 8.0
Front Wheel Material (165) : alloy
Rear Wheel Material (166) : alloy
Spare Wheel Material (167) : alloy
Steering Type (176) : pwr rack & pinion
Steering Ratio (:1), Overall (178) : 16.3
Turning Diameter - Curb to Curb (184) : 37.7
Brake Type (186) : pwr

Notice how the abbreviation pwr can be found in a variety of different contexts: alone, before a set of words, before a dash, etc. How can I create a statement within my foreach code to convert all mentions of pwr to power?

Thanks!

Aucun commentaire:

Enregistrer un commentaire