<?php

$maxlength = 1000000;
$chunklength = 7000;
$tag = "&&&&";
$original = $contenido;

//Validate string - check if tags already exist;

$checker = strstr($original, $tag);

if (!$checker) {
} else {
	echo "Aviso!!  El contenido ya tiene una ocurriencia de lo siguiente: \" ".$tag."\"<br>";
	echo "Favor hacer una busqueda y reemplazo...o contactar al administrador del servidor<br>";
	echo "a <a href=\"mailto:amauris@funredes.org\">amauris@funredes.org</a>.";
	$errorsplitting = "si";
}

//Convert line breaks to HTML entities

$breaks = strstr($contenido, "<br>");
if (!$breaks) {
	$original = nl2br($original);
}

//Parse the string

$original = str_replace("'", "\'", $original);

// Measure String Length to see if it will fit in the DBase

$length = strlen($original);

if ($length > $maxlength) {
	echo "Aviso!!!   El contenido es demasiado largo para caber en nuestro sistema.<br>";
	echo "Favor asegurarse que sea menos de ".$maxlength." bytes o contactar el<br>";
	echo "administrador a <a href=\"mailto:mike@funredes.org\">mike@funredes.org</a>.";
	$errorsplitting = "si";
}

// Count number of pieces

$numberofpieces = $length / $chunklength;

$decimal = explode(".", $numberofpieces);
$numberofpieces = $decimal[0];

if ($decimal[1] > 0) {
	$numberofpieces++;
}

// Chunkafy the String

$newstring = chunk_split($original, $chunklength, $tag);

// Explode the string into various parts and spit them out

$chunk = explode($tag, $newstring);
$chunkcount = count($chunk);


?>
