code snippet: validate string has particular start/end characters

/*
Validate the scriptFileDir by making sure:
  1. It's not too long or short.
  2. It starts with a '/' and ends with a '/'.
*/
$length = strlen($scriptFileDir);
if ($length > 90 OR $length < 1) {
  form_destroy();
  die('Problem with string length. Err 3643348226. -Programmer.');
}

$beginning = strpos($scriptFileDir, '/');
$temp = strrpos($scriptFileDir, '/');
$length = strlen($scriptFileDir);
$end =  $temp - ($length - 1);

if ($beginning !== 0 OR $end !== 0) {
  form_destroy();
  die("The path string does not start and end with a '/' (2087). -Programmer.");
}
Advertisements

About samehramzylabib

See About on https://samehramzylabib.wordpress.com
This entry was posted in PHP Code Snippets, PHP Form Processing, PHP String and tagged , , , . Bookmark the permalink.

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s