How Remove \r\n From String In Php

how remove \r\n from string in php $text = preg_replace(“/\r|\n/”, “”, $text); php remove newline //Replace the newline and carriage return characters //using regex and preg_replace. $text = preg_replace(“/\r|\n/”, “”, $text); Source:thisinterestsme.com string remove line breaks php preg_replace( “/\r|\n/”, “”, $yourString ); Source:stackoverflow.com php remove \t and \n $str = preg_replace(‘/(\v|\s)+/’, ‘ ‘, $str); Source: stackoverflow.com

“Laravel Migration Data Types”

“laravel migration data types” $table->bigIncrements(‘id’); Incrementing ID using a “big integer” equivalent. $table->bigInteger(‘votes’); BIGINT equivalent to the table $table->binary(‘data’); BLOB equivalent to the table $table->boolean(‘confirmed’); BOOLEAN equivalent to the table $table->char(‘name’, 4); CHAR equivalent with a length $table->date(‘created_at’); DATE equivalent to the table $table->dateTime(‘created_at’); DATETIME equivalent to the table $table->decimal(‘amount’, 5, 2); DECIMAL equivalent with … Read more

Laravel Table Data Types

laravel table data types $table->bigIncrements(‘id’); Incrementing ID using a “big integer” equivalent. $table->bigInteger(‘votes’); BIGINT equivalent to the table $table->binary(‘data’); BLOB equivalent to the table $table->boolean(‘confirmed’); BOOLEAN equivalent to the table $table->char(‘name’, 4); CHAR equivalent with a length $table->date(‘created_at’); DATE equivalent to the table $table->dateTime(‘created_at’); DATETIME equivalent to the table $table->decimal(‘amount’, 5, 2); DECIMAL equivalent with … Read more

Php Unset Session Variable

php unset session variable // Destroy a sesion variable name ‘variable_name’ <?php unset($_SESSION[‘variable_name’]); ?> unset session in php session_unset(); //Destrol all session variables

Session Unset

session unset // Destroy a sesion variable name ‘variable_name’ <?php unset($_SESSION[‘variable_name’]); ?> unset session in php session_unset(); //Destrol all session variables learn difference between session unset and session destroy session unset: unset($_SESSION[‘id’]); //remove perticular session variable session destroy: session_destroy(); //remove all session variable

Php Generate Random String Fixed Length

php generate random string fixed length function generateRandomString($length = 25) { $characters = ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’; $charactersLength = strlen($characters); $randomString = ”; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength – 1)]; } return $randomString; } //usage $myRandomString = generateRandomString(5);

Php Parse Float 2 Decimal Places

php parse float 2 decimal places $num = 5; $num = number_format($num, 2); fix to 2 decimal places php return number_format((float)$number, 2, ‘.’, ”); Source:stackoverflow.com php float 2 decimais $foo = “105”; echo number_format((float)$foo, 2, ‘.’, ”); Source: stackoverflow.com

Smarty Assign

smarty assign {assign var=”name” value=”Bob”} {assign “name” “Bob”} {* short-hand *} The value of $name is {$name}. {* Other cool examples *} {foreach $videos as $video} {$video.title_ns = {$video.title|lower|replace:’ ‘:’-‘}} {/foreach} {assign var=”name” value=”somestring_{$item.id}”} Source: www.smarty.net  

Smarty Assign Var

smarty assign var {assign var=”name” value=”Bob”} {assign “name” “Bob”} {* short-hand *} The value of $name is {$name}. {* Other cool examples *} {foreach $videos as $video} {$video.title_ns = {$video.title|lower|replace:’ ‘:’-‘}} {/foreach} {assign var=”name” value=”somestring_{$item.id}”} Source: www.smarty.net  

Disable Admin Bar WordPress

disable admin bar wordpress /* Disable WordPress Admin Bar for all users */ add_filter( ‘show_admin_bar’, ‘__return_false’ ); wordpress make new users not be able to see top bar add_action(‘after_setup_theme’, ‘remove_admin_bar’);   function remove_admin_bar() { if (!current_user_can(‘administrator’) && !is_admin()) {   show_admin_bar(false); } } Source:www.wpbeginner.com remove admin bar wordpress front end /* Disable WordPress Admin Bar for … Read more

Laravel Migation Error

laravel migation error use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); } Source: laravel-news.com  

Pdo Transaction

pdo transaction <?php /* Begin a transaction, turning off autocommit */ $dbh->beginTransaction(); try { /* Change the database schema and data */ $sth = $dbh->exec(“DROP TABLE fruit”); $sth = $dbh->exec(“UPDATE dessert SET name = ‘hamburger’”); } catch(Exception $e){ /* Recognize mistake and roll back changes */ $dbh->rollBack(); } /* Commit changes */ $dbh->commit();