codeboy89 Posted November 22, 2009 Share Posted November 22, 2009 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 More sharing options...
salathe Posted November 22, 2009 Share Posted November 22, 2009 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>"); } Link to comment https://forums.phpfreaks.com/topic/182526-quick-help-compacting-code/#findComment-963399 Share on other sites More sharing options...
codeboy89 Posted November 22, 2009 Author Share Posted November 22, 2009 Thank you sal, I am new and trying to learn. Link to comment https://forums.phpfreaks.com/topic/182526-quick-help-compacting-code/#findComment-963408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.