title: How to detect a delimiter in a string in PHP?
body: <p>I am curious if you have a string how would you detect the delimiter?</p>
  
  <p>We know php can split a string up with explode() which requires a delimiter parameter. </p>
  
  <p>But what about a method to detect the delimiter before sending it to explode function?</p>
  
  <p>Right now I am just outputting the string to the user and they enter the delimiter. That's fine -- but I am looking for the application to pattern recognize for me.</p>
  
  <p>Should I look to regular expressions for this type of pattern recognition in a string?</p>
  
  <p>EDIT: I have failed to initially specify that there is a likely expected set of delimiters. Any delimiter that is probably used in a CSV. So technically anyone could use any character to delimit a CSV file but it is more probable to use one of the following characters: comma, semicolon, vertical bar and a space.</p>
  
  <p>EDIT 2: Here is the workable solution I came up with for a "determined delimiter".</p>
  
  <pre><code>$get_images = "86236058.jpg 86236134.jpg 86236134.jpg";
  
      //Detection of delimiter of image filenames.
          $probable_delimiters = array(",", " ", "|", ";");
  
          $delimiter_count_array = array(); 
  
          foreach ($probable_delimiters as $probable_delimiter) {
  
              $probable_delimiter_count = substr_count($get_images, $probable_delimiter);
              $delimiter_count_array[$probable_delimiter] = $probable_delimiter_count;
  
          }
  
          $max_value = max($delimiter_count_array);
          $determined_delimiter_array = array_keys($delimiter_count_array, max($delimiter_count_array));
  
          while( $element = each( $determined_delimiter_array ) ){
          $determined_delimiter_count = $element['key'];
          $determined_delimiter = $element['value'];
          }
  
          $images = explode("{$determined_delimiter}", $get_images);
  </code></pre>