I’m a self-thought PHP beginner and I’m still learning regular expressions. Here is a problem i encountered with preg_match_all and arrays
my array has exactly the following information:
;;CARLOS||ANDREW||STEPH||SUE||JUDY||HAROLD||JAMES||KATIE||JESSICA;;
What i’m trying to do is display each name individually there are about 250 different names, the array always begins with ;; and always ends with ;; so here is my issue, first my array loads fine but only the first name by doing:
preg_match_all('/^(.+?)\|\|/', $body, $part);
foreach ($part[1] as $part){
print_r($part);
Result is ;;CARLOS
Where $body is the huge list of names (array with 250+ names).
Desired result:
CARLOS
ANDREW
STEPH
JUDY
HAROLD
JAMES
KATIE
JESSICA
Please understand i cannot change the input array, it is what it is. So basically on the first array i have load the entire list then i need to break it by | characters.
Thanks for any advice.
No need to use regular expressions here.
explodeandtrimwill work just fine.Output
See in action.
If you want your desired result exactly, then
implodethe above output.