Question: I have a string that contains some values I need to extract. Each of these values is surrounded by a common character. 

What is the most efficient way to extract all of these values into an array?

For example, given the following string:

```
stackoverflowis%value1%butyouarevery%value2%

```

I would like to get an array containing `value1` and `value2`

Answer: 
```
$s = "stackoverflowis%value1%butyouarevery%value2%";
preg_match_all('~%(.+?)%~', $s, $m);
$values = $m[1];

```

[preg\_match\_all](http://php.net/manual/en/function.preg-match-all.php)
Give a try to explode. Like $array = explode('%', $string);

LE:

```
<?php

$s = 'stackoverflowis%value1%butyouarevery%value2%';
$a = explode('%', $s);
$a = array_filter($a, 'strlen'); // removing NULL values
$last = ''; // last value inserted;
for($i=0;$i<=count($a);$i++)
    if (isset($a[$i+1]) && $a[$i] <> $last)
        $t[] = $last = $a[$i+1];

echo '<pre>'; print_r($t); echo '</pre>';

```