Jump to content

preg_split first item in array is blank


pdug175

Recommended Posts

Hi fert, thanks for the reply. I've not posted all my code because I'm doing some further manipulation with the string. I'm particularly interested why the first item isn't being assigned to $array[0], is there something stupid I'm doing with that code?

i have a feeling that's just how the code works - given that it "splits" on a regex, it will likely return the portion both before and after the match; that includes before the first position and after, which results in the empty first return.  try using:

 

<?php
$array= preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
?>

 

this will tell it to not bother returning any empty matches.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.