Jump to content

Quick help compacting code


codeboy89

Recommended Posts

I just would like to know if anyone can show me if there is any way to do this in fewer lines? Thanks!!

 

if (trim(strip_tags($_POST['cap'])) != $_SESSION['captcha']) {
print "CAPTCHA invalid</div></body></html>";
exit(); }

if (trim(strip_tags(!preg_match("/http:\/\//",$_POST['link'])))) {
print "Link invalid</div></body></html>";
exit(); }

if (( $name == "") || ( $link == "") || ( $cap == "")) {
print "Form not finished</div></body></html>"; 
exit(); }

if (strlen($name) > 25){
print "Name too long</div></body></html>";
exit(); }

if (strlen($link) > 100){
print "Link too long</div></body></html>";
exit(); }

if (strlen($cap) > {
print "CAPTCHA too long</div></body></html>";
exit(); }

Link to comment
https://forums.phpfreaks.com/topic/182526-quick-help-compacting-code/
Share on other sites

Why would fewer lines be an improvement? That said, sure:

 

$error = FALSE;
if (trim(strip_tags($_POST['cap'])) != $_SESSION['captcha']) {
$error = "CAPTCHA invalid";
} elseif ( ! preg_match("/http:\/\//",$_POST['link'])) {
$error = "Link invalid";
} elseif (( $name == "") || ( $link == "") || ( $cap == "")) {
$error = "Form not finished";
} elseif (strlen($name) > 25){
$error = "Name too long";
} elseif (strlen($link) > 100){
$error = "Link too long";
} elseif (strlen($cap) > {
$error = "CAPTCHA too long";
}
if ($error) {
die("$error</div></body></html>");
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.