I have a wrapper for PHPExcel, and I have a method called setColumn()
, which looks like this:
public function setColumn($cell = ""){
if(empty($cell)){
$cell = $this->cell;
}
$this->column = strtoupper(preg_replace("/[^A-Za-z]/", "", $cell));
$this->cell = "{$this->column}{$this->row}";
return $this;
}
It works just fine, but as I use it, I can pass in ranges such as A1:D1
and when I do, my preg_replace will not replace correctly, it will return AD
which I don't want. I want it to return A
. I am not sure of the regular expression needed to accomplish this.
The parameter $cell
can contain a few different values:
-
A1
should returnA
-
A1:D10
should returnA
-
AD10
should returnAD
-
AD1:BBB1
should returnAD
The list could go on, but that is the basics. So what can I do to acomplish that?