PHP Velho Oeste 2024

spliti

(PHP 4 >= 4.0.1, PHP 5)

splitiSepara strings em array utilizando expressões regulares insensíveis a maiúsculas e minúsculas

Aviso

Esta função está OBSOLETA no PHP 5.3.0 e foi REMOVIDA no PHP 7.0.0.

Alternativas a esta função incluem:

Descrição

spliti ( string $pattern , string $string [, int $limit = -1 ] ) : array

Separa uma string em array por expressão regular.

Esta função é idêntica a split() exceto que esta ignora distinção de caracteres alfabéticos maiúsculos e minúsculos.

Parâmetros

pattern

Expressão regular case insensitive.

Se separar caracteres que são consideredos especiais para as expressões regulares, será necessário usar o caracter de escape primeiramente. Se você pensar que split() (ou outra função para execução de expressões regulares) é muito estranha, por favor leia o arquivo regex.7, incluido na pasta regex/ no subdiretório da distribuição do PHP. Está no formato manpage e você deverá usar o comando man /usr/local/src/regex/regex.7 para maiores informações.

string

A string de entrada.

limit

Se limit é definido, o array retornado conterá no máximo limit elementos com o último elemento contendo todo resto da string.

Valor Retornado

Retorna uma matriz de strings, contendo as substrings de string separadas pelos limites descritos na expressão regular case sensitive pattern.

Se existirem n ocorrências da pattern, será retornado uma matriz (array) contendo n+1 items. Por exemplo, se não existir uma ocorrência de pattern, uma matriz com um único elemento será retornado. Certamente, isto também é válido se string estiver vazia. Se um erro ocorrer, split() retorna FALSE.

Exemplos

Este exemplo separa uma string usando 'a' com o separador:

Exemplo #1 Exemplo da spliti()

<?php
$string 
"aBBBaCCCADDDaEEEaGGGA";
$chunks spliti ("a"$string5);
print_r($chunks);
?>

O exemplo acima irá imprimir:

Array
(
  [0] =>
  [1] => BBB
  [2] => CCC
  [3] => DDD
  [4] => EEEaGGGA
)

Veja Também

  • preg_split() - Divide a string por uma expressão regular
  • split() - Separa strings em array utilizando expressões regulares
  • explode() - Divide uma string em strings
  • implode() - Junta elementos de uma matriz em uma string

add a note add a note

User Contributed Notes 3 notes

up
0
jeffmixpute
13 years ago
This example shows the use of spliti.
Here it splits the path of the server as it can be used further.

<?php

require_once 'Beispiel.php';
$seq = new Sequence();

$path = $_SERVER["PATH_INFO"];

echo
"PATH: ".$path."<br/>";
echo
"Request mode: ".$_SERVER["REQUEST_METHOD"]."<br/>";

$daten = spliti ("/", $path);

echo
"get-daten[1] ".$daten[1]."<br/>";

if(
$_SERVER["REQUEST_METHOD"]== "POST"){
  echo
"POST".$daten[1];
 
$seq->setzeSequence($daten[1], $_POST["xml"]);
}
elseif(
$_SERVER["REQUEST_METHOD"] == "DELETE"){
  echo
"DELETE".$daten[1];
 
$seq->loescheSequence($daten[1]);
}
elseif(
$_SERVER["REQUEST_METHOD"] == "GET"){

$antwort = $seq->holeSequence($daten[1]);
  echo
"antwort[0]: ".$antwort[0]."<br/>";
  foreach(
$antwort as $mes){
   echo
"mes ".$mes."<br/>";
   }
}

?>
up
0
Anonymous
20 years ago
When using special characters such as the tab placeholder "\t" in the split function, be careful not to escape the slash by adding a slah in front of it. To signify a tab, new line or carriage return use only one slash in front of the character. For example:

$cartes= "one\ttwo\tthree";

$tab_cartes = split("\t",$cartes );

$items = count($tab_cartes);
for ($x = 0; $x < $items; $x++)
   { echo $tab_cartes[$x] . "\n"; }
up
0
vbelon at hotmail dot com
20 years ago
To split $cartes which contains data and tabulations:
Doesnt work :
$tab_cartes = split("\\t",$cartes );

But \t = char(9), so, works well:
$tab_cartes = split(Chr(9),$cartes);

Idem for :
\n = char(10)
\r = char(13)

Found in http://www.asp-magazine.com/fr/asp/blitz/blitz4.asp
To Top