PHP parse error "syntax error, unexpected '['" -
this question has answer here:
- php parse/syntax errors; , how solve them? 12 answers
i confused because wrote code , in virtual server php worked fine when download on server got parse error , don't know how deal it.
error on line 8 $tosearch ,parse error: syntax error, unexpected '['
here code :
<?php function decodename($name) { if (substr($name,0,2)=="p_") { $name = substr($name,2); } $tosearch=["_c_","_s_","_q_","_d_","_p_","_e_","_lp_","_rp_","_"]; $toreplace=[",","/","\"",".","-","=","(",")"," "]; ($i=0; $i<count($toreplace); $i++) { $name = str_replace($tosearch, $toreplace, $name); } return $name; } function codename($name, $addprefix = 0) { if (substr($name,0,2)=="p_") { $name = substr($name,2); } $toreplace=["_c_","_s_","_q_","_d_","_p_","_e_","_lp_","_rp_","_"]; $tosearch=[",","/","\"",".","-","=","(",")"," "]; ($i=0; $i<count($toreplace); $i++) { $name = str_replace($tosearch, $toreplace, $name); } if ($addprefix >0) { $name = "p_".$name; } return $name; } function getids($xml_handle, $nametosearch) { $matches=array(); $id =$xml_handle->getelementsbytagname('wva'); $id2 = $xml_handle->getelementsbytagname('wva2'); $nametosearch = codename($nametosearch,0); ($i = 0; $i < $id->length; $i++) { $id = $id->item($i); $id2 = $id2->item($i); if ($id->nodevalue==$nametosearch) { array_push($matches,$id->parentnode); } elseif ($id2->nodevalue==$nametosearch) { array_push($matches,$id2->parentnode); } } return $matches; } function getmodeldetails($xml_handle, $modelname) { $modeldetails = array(); $modelname = codename($modelname,1); $model = $xml_handle->getelementsbytagname($modelname); $model = $model -> item(0); $model = $model -> childnodes; ($i=0; $i<$model->length; $i++) { $modeldetails[$i]=decodename($model -> item($i)->nodevalue); } return $modeldetails; } ?>
short array syntax supported php 5.4
$fruits = ['apples', 'oranges', 'bananas']; // associative array $array = [ 'foo' => 'bar', 'bar' => 'foo' ];
old way:
$fruits = array('apples', 'oranges', 'bananas');
Comments
Post a Comment