如何获取公司列表的名称?

How to get the names of a list of companies?

我想创建一个函数来简化公司名称(例如,Apple Inc.、Microsoft Corporation、Advanced Micro Devices, Inc.),并创建一个小写字符串以嵌入 URL(例如,苹果、微软、高级微型设备)。

function cleanCompany($companyName){
  $companyName= strtolower($companyName);
  $companyName=preg_replace('/(!||&||,||\.||\'||\"||\(||\))/i', '', $companyName);
  $companyName=str_replace(array('company',' corporation',', inc.',' inc.',' inc',' ltd.',' limited',' holding',' american depositary shares each representing one class a.',' american depositary shares each representing one class a',' american depositary shares each representing two',' american depositary shares each representing 2',' class a',' s.a.'), '', $companyName);
  $companyName=preg_replace('/(\s+)/i', '-', $companyName);
  return $companyName; 
}

公司名称在此link:https://iextrading.com/trading/eligible-symbols/

这个函数仍然有问题,我正在尝试解决它:

$companyName=str_replace(array('---','--'), array('-'), $companyName);

如何改进此功能或完成此任务?

根据Barmar的建议,我修改了函数,效果不错。

function slugCompany($c){
  $c= strtolower($c);
  $c=preg_replace('/[^\da-z\s]/i', '', $c);
  $c=str_replace(array('company',' corporation',', inc.',' inc.',' inc',' ltd.',' limited',' holding',' american depositary shares each representing one class a.',' american depositary shares each representing one class a',' american depositary shares each representing two',' american depositary shares each representing 2',' class a',' s.a.'), '', $c);
  $c=preg_replace('/(\s+)/i', '-', $c);
  return $c; 
}

此外,我添加了一个循环来将 '--' 替换为 '-'

for ($i=0; $i < 5; $i++) { 
  if(strpos($c,'--')!==false){
    $c=str_replace('--','-', $c);
  }else{
    break;
  }
}

另一种方法,我试过了

function slugCompany($c){
  $c= strtolower($c);
  $c=preg_replace('/[^\da-z\s]/i', '', $c);
  $words='11000th|american|and|a|beneficial|bond|b|class|common|company|corporation|corp|commodity|cumulative|co|c|daily|dep|depositary|depository|debentures|diversified|due|d|each|etf|equal|equity|exchange|e|financial|fund|fixedtofloating|fixed|floating|f|group|g|healthcare|holdings|holding|h|inc|incorporated|interests|interest|in|index|income|i|junior|j|k|liability|limited|lp|llc|ltd|long|l|markets|maturity|municipal|muni|monthly|m|noncumulative|notes|no|n|of|one|or|o|portfolio|pay|partnership|partner|par|perpetual|per|perp|pfd|preference|preferred|p|q|redeemable|repstg|representing|represents|rate|r|sa|smallcap|series|shs|shares|share|short|stock|subordinated|ser|senior|s|the|three|term|to|traded|trust|two|t|ultrashort|ultra|u|value|v|warrant|weight|w|x|y|z';
  $c=preg_replace('/\b('.$words.')\b/i', '', $c);
  $c=preg_replace('/(\s+)/i', '-', trim($c));
  return $c; 
}