Category : string

I try to import JSON formatted file into MySQL database. I put this code in the web.php: Route::get(‘/pages’, function(){ $json = file_get_contents(storage_path(‘posts_and_comments.json’)); $objs = json_decode($json,true); foreach ($objs as $obj) { foreach ($obj as $key => $value) { $insertArr[Str::slug($key,’_’)] = $value; } DB::table(‘my_likes’)->insert($insertArr); } dd("Finished adding data in examples table"); }); It gave me a ErrorException ..

Read more

I want to split at every ‘;’ and every ‘{‘ from the string below: // string $str = ‘abc;def;ghi{jkl;}if(‘mno’) {pqr;}’; // expression $pattern = "/[;{(]/"; $result = preg_split($pattern); print_r($result); It splits at the point of every ‘;’ and ‘{‘ but these characters are also removed which I don’t want. I used explode() function though it ..

Read more

I have this js code: var my_elem = document.querySelector("[action=’/cart/add’]"); but I need to make it a string, so I can use it as a string variable. How I can do that? I already tried: ‘var my_elem = document.querySelector("[action=’/cart/add’]");’ but I got an error: syntax error, unexpected ‘"’) === true) {‘ (T_CONSTANT_ENCAPSED_STRING) Sourc..

Read more

Strings Error With Foreign Keys ID is working fine name, lastname, email is having a problem initializing. *"Foreign key constraint is incorrectly formed") (SQL: alter table login_logs add constraint login_logs_name_foreign foreign key (name) references users (name)) * User Table: public function up() { Schema::create(‘users’, function (Blueprint $table) { $table->id(); $table->string(‘name’); $table->string(‘lastname’); $table->string(‘mobile’); $table->string(’email’)->unique(); $table->timestamp(’email_verified_at’)->nullable(); $table->string(‘password’); ..

Read more

i get this """ <p><b>Title</b></p>rn rn <p>Is anyone else having problems with latecomers even with the later time start of 10.30?</p>rn rn <p>Also I am still certain people are doing night shifts before they attend courses. Anyone concur?</p>rn rn <p>&nbsp;</p>rn """ format in my o/p and i want to add font-size class into these all ..

Read more

ok is a little bit rude code but why ive this output on this simple string formatting sample? foreach (Transaction::where(‘customer’,$id)->cursor() as $ftr) { $origValue=$ftr->value; $currency= mb_substr($origValue, 0, 1, "UTF-8"); $value = substr($origValue, 1); dd($value); // } $originalValue is equal for example to "$50.00"; $currency is setted correctly to "$"; $value should be "50.00" but this ..

Read more

The following code returns always the first value as selected, rather than empty! <select class="select2" autocomplete="off" name="{{$field_name}}"> <option></option> @foreach(explode(‘,’, "a,b,c") as $key=> $value) <option value='{{$key}}’ @if (old($field_name) == $key) selected="selected" @endif>{{$value}}</option> @endforeach </select> Somehow, the old($field_name) == $key returns 0 which makes the select statement always puts the first option as the selected, instead of ..

Read more

I’ve been trying to make the first letter of a string in the capital but I can’t get it to work. I have tried the following code: <?php $str = $_POST[‘Papier’]; $f = highlightKeywords(‘papierwaren’, $str); $s = strtolower($f); $r = ucfirst($s); function highlightKeywords($text, $keyword) { $pos = strpos($text, $keyword); $wordsAry = explode(" ", $keyword); $wordsCount ..

Read more