{"id":210,"date":"2012-02-07T11:46:12","date_gmt":"2012-02-07T11:46:12","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=210"},"modified":"2022-06-23T11:08:33","modified_gmt":"2022-06-23T10:08:33","slug":"verifying-strings","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/strings\/verifying-strings","title":{"rendered":"Using Strings-Verifying Strings"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Is String Numeric<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (filter_var($MyString, FILTER_VALIDATE_INT) !== False)\n  {\n    \/\/String is an int\n  }\n   \n    \n  if (is_numeric($MyString))\n  {\n    \/\/String is numeric\n  }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Is String A Date Time<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  if(strtotime($MyDateTimeString))    \/\/Returns timestamp on success, false otherwise\n    \/\/String is in date \/ time format<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Is String Within An Array Of Strings<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$MyArrayOfStrings = array ('abcd', 'efgh', 'ijkl' );\nif (in_array($MyStringToCheck, $MyArrayOfStrings))\n{\n\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Check Entered Web Address<\/h4>\n\n\n\n<p><strong><em>This isn&#8217;t right &#8211; the first test rejects doamins with a hyphen in them<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $domain_name = trim(@mysql_real_escape_string($domain_name));\n\n  if (!eregi(\"^&#91;_a-zA-Z0-9\\-\\.]*$\", $domain_name))\n  {\n    $message = \"Invalid character(s) in the Domain Name\";\n  }\n  elseif (!eregi(\"^&#91;a-zA-Z0-9-]+(\\.&#91;a-zA-Z0-9-]+)*(\\.&#91;a-z]{2,3})$\", $domain_name))\n  {\n    $message = \"Invalid domain name format\";\n  }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Verify Email Address<\/h4>\n\n\n\n<p>A thorough version from <a href=\"http:\/\/www.linuxjournal.com\/article\/9585\" target=\"_blank\" rel=\"noopener noreferrer\">this article here<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/*****************************************\n\/\/*****************************************\n\/\/********** CHECK EMAIL ADDRESS **********\n\/\/*****************************************\n\/\/*****************************************\nfunction check_email_address($email)\n{\n  \/\/First, we check that there's one @ symbol, and that the lengths are right.\n  if (!ereg(\"^&#91;^@]{1,64}@&#91;^@]{1,255}$\", $email))\n\t{\n    \/\/Email invalid because wrong number of characters in one section or wrong number of @ symbols.\n    return false;\n  }\n\t\n  \/\/Split it into sections to make life easier\n  $email_array = explode(\"@\", $email);\n  $local_array = explode(\".\", $email_array&#91;0]);\n  for ($i = 0; $i &lt; sizeof($local_array); $i++)\n\t{\n    if (!ereg(\"^((&#91;A-Za-z0-9!#$%&amp;'*+\/=?^_`{|}~-]&#91;A-Za-z0-9!#$%&amp;'*+\/=?^_`{|}~\\.-]{0,63})|(\\\"&#91;^(\\\\|\\\")]{0,62}\\\"))$\", $local_array&#91;$i]))\n\t\t{\n      return false;\n    }\n  }\n\t\n  \/\/Check if domain is IP. If not, it should be valid domain name\n  if (!ereg(\"^\\&#91;?&#91;0-9\\.]+\\]?$\", $email_array&#91;1]))\n\t{\n    $domain_array = explode(\".\", $email_array&#91;1]);\n    if (sizeof($domain_array) &lt; 2)\n\t\t{\n      return false; \/\/ Not enough parts to domain\n    }\n\t\t\n    for ($i = 0; $i &lt; sizeof($domain_array); $i++)\n\t\t{\n      if (!ereg(\"^((&#91;A-Za-z0-9]&#91;A-Za-z0-9-]{0,61}&#91;A-Za-z0-9])|(&#91;A-Za-z0-9]+))$\", $domain_array&#91;$i]))\n\t\t\t{\n        return false;\n      }\n    }\n  }\n\t\n  return true;\n}<\/code><\/pre>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">&nbsp;<\/pre>\n<\/div><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code><\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Is String Numeric Is String A Date Time Is String Within An Array Of Strings Check Entered Web Address This isn&#8217;t right &#8211; the first test rejects doamins with a hyphen in them Verify Email Address A thorough version from this article here &nbsp;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-strings"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":15,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":4299,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/210\/revisions\/4299"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}