Forum Moderators: coopster
<?php
$reg = $_POST['reg'];
$arname = $_POST['arname'];
$cont = $_POST['content'];
$contl = preg_replace('/[\r\n]{2}/m', '|##/|\##|', $cont);
if(isset($reg) && $reg != "") {
$slash = '/';
$sel = ' checked';
}
if((isset($cont) && $cont != "") && (isset($arname) && $arname != "")) {
$contl = explode("|##/|\##|", $contl);
$rows = count($contl);
$out = '<textarea class="out" onfocus="select();">$' . $arname . ' = array();';
for($i = 0; $i < $rows; $i++){
if(!preg_match("/'/", $contl[$i])) {
$out .= "\n" . '$' . $arname . '[' . $i . '] = '' . $slash . preg_replace('/[\/\\\\]"/', '"', $contl[$i]) . $slash . '';';
} elseif(!preg_match('/"/', $contl[$i])) {
$out .= "\n" . '$' . $arname . '[' . $i . '] = "' . $slash . preg_replace("/[\/\\\\]'/", ''', $contl[$i]) . $slash . '";';
} else {
$out .= "\n" . '$' . $arname . '[' . $i . '] = ' . $slash . preg_replace('/[\/\\\\]"/', '"', preg_replace("/[\/\\\\]'/", ''', $contl[$i])) . $slash . ' ERROR: APOSTROPHEE AND QUOTATION';
}
}
$out .= '</textarea>';
}
$cont = '<html>
<head>
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
<title>Array builder</title>
<style type="text/css">
input {border: #000 1px solid;padding: 1px;background-color: #ccc;font-size: 11px;color: #000;font-family: Verdana;width: 207px;}
input.check {border: 0px;padding: 0px;background-color: #fff;width: 13px;}
textarea {border: 1px solid;padding: 1px;background-color: #fff;font-size: 11px;color: #000;font-family: Lucida Console;height: 300px;width: 300px;overflow: auto;}
textarea.out {padding: 5px;background-color: #ccc;font-size: 11px;width: 400px;}
span {font-size: 11px;color: #000;font-family: Verdana;}
</style>
</head>
<body>
<span><b>Array builder</b><br><br>Created by Michael Read<br>Contact me by sending a PM to Readie at webmasterworld.com<br>This tool may be used freely for all purposes and without citation<hr><br>Enter each new array value on a new line.</span>
<form method="post">
<span><b>Array name: $</b></span><input type="text" name="arname" value="' . $arname . '"><br>
<textarea name="content">' . preg_replace("/[\/\\\\]'/", "'", preg_replace('/[\/\\\\]"/', '"', $cont)) . '</textarea><br>
<span>Regex:</span><input class="check" type="checkbox" name="reg" value="yes"' . $sel . '><br>
<input type="submit" value="Create array">
</form>' . $out . '
</body>
</html>';
echo $cont;
?>