{"id":137,"date":"2012-02-04T00:18:53","date_gmt":"2012-02-04T00:18:53","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=137"},"modified":"2012-02-04T00:18:53","modified_gmt":"2012-02-04T00:18:53","slug":"php-validate-twitter-username","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/php-validate-twitter-username\/","title":{"rendered":"PHP Validate Twitter Username Example"},"content":{"rendered":"<p>If you want to validate Twitter username using PHP i.e check whether its\u00a0available\u00a0for registration or not, this can be easily achieved using CURL. The following function will check whether twitter username exists for registration or if it is already registered.<!--more--><\/p>\n<h2>How to Validate Twitter Username using PHP<\/h2>\n<p>Use the following code to validate Twitter Username using PHP:<\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\nfunction validate_twitter_username($username)\n{\n$twitter_url='http:\/\/api.twitter.com\/1\/users\/show\/'.$username.'.xml';\n\n$init = curl_init();\ncurl_setopt ($init, CURLOPT_URL, $twitter_url);\ncurl_setopt ($init, CURLOPT_CONNECTTIMEOUT, 20);\ncurl_setopt($init, CURLOPT_NOBODY, 1);\ncurl_setopt($init, CURLOPT_HEADER, 1);\ncurl_setopt($init, CURLOPT_RETURNTRANSFER, true);\n\ncurl_exec($init);\n$result_header = curl_getinfo($init, CURLINFO_HTTP_CODE);\ncurl_close($init);\n\n\/\/ IF username does note exist, then it means its avilable for registration\nif( '404' == $result_header )\n{\nreturn 'Username is available.';\n}\nelse\n{\n\/\/ This means username is already taken\nreturn 'Username already taken.';\n}\n}\n\n\/\/Enter the username you want to check below and that's it.\n$username = 'extreme';\n\necho validate_twitter_username($username);\n?&gt;<\/pre>\n<h5>That&#8217;s it!<\/h5>\n<p>Do you know a simpler way to <strong>validate twitter username?<\/strong> If yes, please share it with us in your comments below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to validate Twitter username using PHP i.e check whether its\u00a0available\u00a0for registration or not, this can be easily achieved using CURL. The following function will check whether twitter username exists for registration or if it is already registered.<\/p>\n","protected":false},"author":1,"featured_media":141,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7,10,6,13],"tags":[32,33],"class_list":["post-137","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","category-php-tips-and-tricks","category-snippets","category-tips-and-tricks","tag-php-snippets","tag-php-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-2d","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=137"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/137\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}