{"id":4838,"date":"2021-12-13T07:00:00","date_gmt":"2021-12-13T01:30:00","guid":{"rendered":"https:\/\/selfimagination.in\/tips\/?p=4838"},"modified":"2022-07-19T16:04:35","modified_gmt":"2022-07-19T10:34:35","slug":"php-most-useful-codes-to-use-while-coding","status":"publish","type":"post","link":"https:\/\/selfimagination.in\/tips\/php-most-useful-codes-to-use-while-coding\/","title":{"rendered":"PHP : Most Useful Codes to use while coding"},"content":{"rendered":"\n<p>\u091c\u092c \u092d\u0940 \u0906\u092a PHP \u092e\u0947 \u0915\u094b\u0921\u093f\u0902\u0917 \u0915\u0930\u0947\u0902\u0917\u0947 \u0924\u094b \u0906\u092a\u0915\u094b \u092c\u0939\u0941\u0924 \u0938\u0947 Code \u0915\u0940 \u091c\u0930\u0942\u0930\u0924 \u0939\u094b\u0917\u0940 \u091c\u093f\u0938\u0947 \u0915\u0940 \u092f\u093e\u0926 \u0930\u0916 \u092a\u093e\u0928\u093e \u092e\u0941\u0936\u094d\u0915\u093f\u0932 \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u0964 \u0907\u0938 \u092a\u0947\u091c \u092e\u0947 \u0935\u0939 \u0938\u092d\u0940 Most Useful Codes \u0939\u0948\u0902 \u091c\u093f\u0928\u0915\u0940 \u091c\u0930\u0942\u0930\u0924 Code \u0932\u093f\u0916\u0924\u0947 \u0938\u092e\u092f \u0932\u0917\u0924\u0940 \u0939\u0948\u0902 \u0913\u0930 \u092c\u093e\u0930 \u092c\u093e\u0930 Internet \u092a\u0930 \u0938\u0930\u094d\u091a \u0915\u0930\u0928\u0947 \u092e\u0947 \u0938\u092e\u092f \u091c\u094d\u092f\u093e\u0926\u093e \u0932\u0917\u0924\u093e \u0939\u0948\u0902 \u0964 \u0938\u092e\u092f \u0915\u094b \u092c\u091a\u093e\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u092f\u0939 Article \u0932\u093f\u0916\u093e \u0917\u092f\u093e \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">UTF Support <\/h2>\n\n\n\n<p>\u092f\u0926\u093f \u0906\u092a \u0905\u092a\u0928\u0947 \u0915\u093f\u0938\u0940 \u092d\u0940 \u092a\u0947\u091c \u092e\u0947 \u0939\u093f\u0928\u094d\u0926\u0940 Unicode \u092e\u0947 Value Type \u0915\u0930\u0935\u093e\u0928\u093e \u091a\u093e\u0939\u0924\u0947 \u0939\u0948\u0902 \u0924\u094b \u0906\u092a\u0915\u094b Page Header \u092a\u0930 \u0915\u0941\u091b \u0907\u0938 \u092a\u094d\u0930\u0915\u093e\u0930 \u0938\u0947 \u0932\u093f\u0916\u0928\u093e \u0939\u094b\u0917\u093e \u0964 (PHP Code)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">header('Content-Type: text\/html; charset=utf-8');<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Mobile Browser Support <\/h2>\n\n\n\n<p>\u092f\u0926\u093f \u0906\u092a Web Page \u0915\u094b Mobile View \u092a\u0930 \u092d\u0940 \u0926\u0947\u0916\u0928\u093e \u091a\u093e\u0939\u0924\u0947 \u0939\u0948\u0902 \u0924\u094b \u0906\u092a\u0915\u094b \u092f\u0939 Line \u0932\u093f\u0916\u0928\u093e \u0939\u094b\u0917\u0940 \u0964 (Html Code) <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Date Format Change <\/h2>\n\n\n\n<p>Date \u0915\u0947  <strong>yyyy-mm-dd<\/strong> Format \u0915\u094b  <strong>dd-mm-yyyy<\/strong> \u092e\u0947 \u092c\u0926\u0932\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0907\u0938 Code \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0947 (PHP Code)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">$show_date = substr($ls_dt,8,2) .'-'.substr($ls_dt,5,2) .'-'. substr($ls_dt,0,4) ;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Image Code <\/h2>\n\n\n\n<p>PHP Code \u0938\u0947 Image \u0932\u0917\u093e\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0909\u0938 Code \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">echo '&lt;img  width=\"100%\" height=\"auto\" src=\"'.$path.'\"&gt;&lt;\/img&gt;';<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Using DbCmd <\/h2>\n\n\n\n<p>\u092f\u0926\u093f \u0915\u0947\u0935\u0932 \u090f\u0915 \u0939\u0940 Column \u0915\u0940 Value Return \u0915\u0930\u0928\u093e \u0939\u0948\u0902 \u0924\u094b \u0906\u092a \u0907\u0938 Query \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902, \u0907\u0938\u0915\u0947 \u0932\u093f\u090f \u090f\u0915 Class DbCmd \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0928\u093e \u0939\u094b\u0917\u093e <a href=\"https:\/\/selfimagination.in\/tips\/dbcmd\/\">\u091c\u093e\u0928\u0915\u093e\u0930\u0940 \u0915\u0947 \u0932\u093f\u090f \u0915\u094d\u0932\u093f\u0915 \u0915\u0930\u0947<\/a>  <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">\/\/ Return Single Row and Single Column Value\n$ls_SQL1 = \"SELECT ColumnName FROM TableName WHERE whereclause limit 0,1\";\n$val = $dbc-&gt;query_cnt($ls_SQL1);\necho 'Value of Column' . $val;\n<\/code><\/pre>\n\n\n\n<p>\u090f\u0915 \u0938\u0947 \u0905\u0927\u093f\u0915 Columns \u0914\u0930 Rows \u0915\u0940 Value \u0915\u094b Get \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0939\u092e\u0947 \u0907\u0938 Code \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0928\u093e \u091a\u093e\u0939\u0924\u0947 \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">$ls_SQL2 = \"SELECT List of Columns FROM TableName WHERE whereclause\"; \n$result = $dbc-&gt;query($ls_SQL2);\nwhile ($row = mysqli_fetch_array($result)) \n{\n   echo 'Value 1:' . $row[\"column1\"] ;\n   echo 'Value 2:' . $row[\"column2\"] ;\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">JSON<\/h2>\n\n\n\n<p>Json \u0915\u0940 Value \u0915\u094b Decode \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">$ObjS = json_decode($sVal);              \n$Val1 = $ObjS-&gt;val1; \n$Val2 = $ObjS-&gt;val2;<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/selfimagination.in\/tips\/json-encode\/\">Json \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947 \u091c\u093e\u0928\u0915\u093e\u0930\u0940 \u0915\u0947 \u0932\u093f\u090f \u092f\u0939 Article \u0926\u0947\u0916\u0947 <\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u0939\u092e-\u0930-\u0905\u0928-\u092f-\u0906\u0930-\u091f-\u0915\u0932\"><strong>\u0939\u092e\u093e\u0930\u0947 \u0905\u0928\u094d\u092f \u0906\u0930\u094d\u091f\u093f\u0915\u0932<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/selfimagination.in\/tips\/mysql-function\/\">MySQL Function<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/mysql-stored-procedure\/\">MySQL Stored Procedure<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/get-post-method\/\">PHP Get \/Post Method \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u091c\u093e\u0928\u0947<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/php-math-function\/\">PHP Math Function \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u091c\u093e\u0928\u0947<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/learn-cpp-from-c\/\">C \u0938\u0947 C ++ \u0938\u0940\u0916\u0947 \u0938\u0930\u0932 \u0936\u092c\u094d\u0926\u094b\u0902 \u092e\u0947\u0902<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/php-variables\/\">PHP Variable \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u091c\u093e\u0928\u0947<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/arduino-control-structure\/\">Arduino Control Structure<\/a>\u00a0<\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/c-union\/\">Union in C<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/c-pointer\/\">Declaration of Pointer in C<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/search-jquery\/\">jQuery Search Filter<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/mysql-table-create-alter-drop\/\">MySQL Create Table | Alter Table | Drop Table<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/api-using-node-react-express-mysql\/\">API Using NODE REACT EXPRESS MYSQL SEQUELIZE (For Backend OR Server Side)<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/cpanel\/\">CPANEL In Hindi<\/a><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">File Upload <\/h2>\n\n\n\n<p>File Upload \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0906\u092a \u0907\u0938 Code \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">$v = move_uploaded_file($SourceFile, $TargetFileName );<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/selfimagination.in\/tips\/php-file-upload\/\">File upload Advance Function \u0915\u0947 \u0932\u093f\u090f \u092f\u0939\u093e \u092a\u0930 \u0915\u094d\u0932\u093f\u0915 \u0915\u0930\u0947 <\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Validation <\/h2>\n\n\n\n<p>Validation \u0915\u0947 \u0932\u093f\u090f \u0907\u0938 Code \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0947 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">function CommonValidation($value)\n{\n\t$value = trim($value);\n\t$value = htmlspecialchars($value);\n\t$value = stripslashes($value);\n\treturn $value;\n}<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/selfimagination.in\/tips\/php-validation-filter-var-preg_match\/\">Email, PAN, GSTIN validation \u0915\u0947 \u0932\u093f\u090f \u092f\u0939\u093e \u092a\u0930 \u0915\u094d\u0932\u093f\u0915 \u0915\u0930\u0947 <\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">AJAX<\/h2>\n\n\n\n<p>Javascript \u0938\u0947 PHP \u092a\u0947\u091c Call \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f AJAX<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">function GetLoad()\n{ \n   var a1 = 10;\n   var a2 = 20;\n   \/\/   var formData   = $('#FrmLogin').serialize()  \/\/Read Value From Form \n   var formData   = {q:a1, o1:a2};  \/\/Parameter for POST\n\t\t\t\t\n   $.ajax({\n      url : URL,\n      type: \"POST\",\n      data : formData,\n      success: function(data, textStatus, jqXHR)\n      {\n         $(\"#DivID\").html(data);\n      },\n      error: function (jqXHR, textStatus, errorThrown)\n      {\n\n         \/\/Error Message\n      }\n   });\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">HTML Table Fill by MySQL using PHP<\/h2>\n\n\n\n<p>Table \u092e\u0947 SQL \u0938\u0947 Data \u0926\u093f\u0916\u093e\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f PHP Code <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">echo '&lt;table id=\"tab\"&gt;';\necho '&lt;tr&gt;';\necho '&lt;th&gt;ColHead 1&lt;\/th&gt;&lt;th&gt;ColHead 2&lt;\/th&gt;&lt;th&gt;ColHead 3&lt;\/th&gt;&lt;th&gt;ColHead 4&lt;\/th&gt;';\necho '&lt;\/tr&gt;';\n\n\n$ls_SQL2 = \"SELECT List of Columns FROM TableName WHERE whereclause\"; \n$result = $dbc-&gt;query($ls_SQL2);\n\nwhile ($row = mysqli_fetch_array($result)) \n{\n\t$col1   = $row[\"col1\"];\n\t$col2   = $row[\"col2\"];\n\t$col3   = $row[\"col3\"];\n\t$col4   = $row[\"col4\"];\n   echo '&lt;tr&gt;';\n   echo '&lt;td&gt;'.$col1.'&lt;\/td&gt;&lt;td&gt;'.$col2.'&lt;\/td&gt;&lt;td&gt;'.$col3.'&lt;\/td&gt;&lt;td&gt;'.$col4.'&lt;\/td&gt;';\n\n   echo '&lt;\/tr&gt;';\n}\necho '&lt;\/table&gt;';\n<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/selfimagination.in\/tips\/dbcmd\/\">Download DbCmd <\/a><\/p>\n\n\n\n<p>\u0909\u092a\u0930\u094b\u0915\u094d\u0924 Code \u0915\u0947 \u0932\u093f\u090f \u0906\u092a\u0915\u094b \u0939\u092e\u093e\u0930\u0947 \u0926\u094d\u0935\u093e\u0930\u093e \u092c\u0928\u093e\u0908 \u0917\u0908 DbCmd Class \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0928\u093e \u0939\u094b\u0917\u093e , <\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u0906\u0936\u093e \u0939\u0948\u0902 \u092e\u0941\u091d\u0947 \u092f\u0939 Article <strong>PHP : Most Useful Codes to use while coding <\/strong>\u0906\u092a\u0915\u094b PHP \u092e\u0947 Coding \u0915\u0930\u0924\u0947 \u0938\u092e\u092f \u092c\u0939\u0941\u0924 \u092e\u0926\u0926 \u0915\u0930\u0947\u0917\u093e \u0924\u093e\u0915\u093f \u0906\u092a \u0915\u092e \u0938\u092e\u092f \u092d\u0940 \u0905\u0927\u093f\u0915 Coding \u0915\u0930 \u092a\u093e\u090f \u0964 <\/p>\n\n\n\n<p>\u092f\u0939 \u0906\u0930\u094d\u091f\u093f\u0915\u0932 \u0906\u092a\u0915\u094b \u0915\u0948\u0938\u093e \u0932\u0917\u093e \u0939\u092e\u0947 \u091c\u0930\u0942\u0930 \u092c\u0924\u093e\u090f \u0964 <\/p>\n\n\n\n<p>\u0905\u092a\u0928\u093e \u0915\u0940\u092e\u0924\u0940 \u0938\u092e\u092f \u0926\u0947\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0927\u0928\u094d\u092f\u0935\u093e\u0926 <\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u091c\u092c \u092d\u0940 \u0906\u092a PHP \u092e\u0947 \u0915\u094b\u0921\u093f\u0902\u0917 \u0915\u0930\u0947\u0902\u0917\u0947 \u0924\u094b \u0906\u092a\u0915\u094b \u092c\u0939\u0941\u0924 \u0938\u0947 Code \u0915\u0940 \u091c\u0930\u0942\u0930\u0924 \u0939\u094b\u0917\u0940 \u091c\u093f\u0938\u0947 \u0915\u0940 \u092f\u093e\u0926 \u0930\u0916 \u092a\u093e\u0928\u093e \u092e\u0941\u0936\u094d\u0915\u093f\u0932 \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u0964 \u0907\u0938 \u092a\u0947\u091c \u092e\u0947 \u0935\u0939 \u0938\u092d\u0940 Most Useful Codes \u0939\u0948\u0902 \u091c\u093f\u0928\u0915\u0940 \u091c\u0930\u0942\u0930\u0924 Code \u0932\u093f\u0916\u0924\u0947 \u0938\u092e\u092f \u0932\u0917\u0924\u0940 \u0939\u0948\u0902 \u0913\u0930 \u092c\u093e\u0930 \u092c\u093e\u0930 Internet \u092a\u0930 \u0938\u0930\u094d\u091a \u0915\u0930\u0928\u0947 \u092e\u0947 \u0938\u092e\u092f \u091c\u094d\u092f\u093e\u0926\u093e \u0932\u0917\u0924\u093e \u0939\u0948\u0902 \u0964 \u0938\u092e\u092f \u0915\u094b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4986,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-4838","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2021\/11\/php-most-useful-codes.jpg?fit=1200%2C628&ssl=1","_links":{"self":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/4838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/comments?post=4838"}],"version-history":[{"count":22,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/4838\/revisions"}],"predecessor-version":[{"id":8731,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/4838\/revisions\/8731"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media\/4986"}],"wp:attachment":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media?parent=4838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/categories?post=4838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/tags?post=4838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}