“PHP Split String in zwei Hälften” Code-Antworten

PHP -Split -Array in zwei Hälften

$alphabet = array("a", "b", "c", "d", "e","f");

$firsthalf = array_slice($alphabet, 0, count($alphabet) / 2);
$secondhalf = array_slice($alphabet, count($alphabet) / 2);
Friendly Hawk

PHP Split String in zwei Hälften

$text = "The Quick : Brown Fox Jumped Over The Lazy / Dog";

$splitstring1 = substr($text, 0, floor(strlen($text) / 2));
$splitstring2 = substr($text, floor(strlen($text) / 2));

if (substr($splitstring1, 0, -1) != ' ' AND substr($splitstring2, 0, 1) != ' ')
{
    $middle = strlen($splitstring1) + strpos($splitstring2, ' ') + 1;
}
else
{
    $middle = strrpos(substr($text, 0, floor(strlen($text) / 2)), ' ') + 1;    
}

$string1 = substr($text, 0, $middle);  // "The Quick : Brown Fox Jumped "
$string2 = substr($text, $middle);  // "Over The Lazy / Dog"
Amused Alpaca

Ähnliche Antworten wie “PHP Split String in zwei Hälften”

Fragen ähnlich wie “PHP Split String in zwei Hälften”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen