explode

  • We can split a string by a delimiting string in Ruby using String#split. Ruby uses this same method to perform regular expression based splits. See preg_match for examples.

    PHP

    $result = explode("; ", "derek@example.com; mike@example.com");
    var_export($result);
    // => array(0 => 'derek@example.com', 1 => 'mike@example.com')

    Ruby

    p "derek@example.com; mike@example.com".split("; ")
    # => ["derek@example.com", "mike@example.com"]

    see also

Looking for Rails or PHP web application development, integration, and training?

Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.