Remove first and last char from string

Some other possibilities:

Using substr:

$dataList = substr($dataList, 1, -1);

You can also choose to not remove the * from the string but rather remove the empty array values which will always be the first and last element. Using array functions array_pop() and array_shift():

$arrData = array_pop(array_shift($arrData));

Using trim:

trim($dataList, '*');

This will remove all * characters (even if there are more than one!) from the end and the beginning of the string.


$string = substr($dataList, 1, -1);

Remove the first and the last character of the string in php

Tags:

Php

Trim