Category : string

I have a string (trimmed) and i would like to split this string according to a predefined pattern. I wrote a code which is probably more interpretive. $string="123456789"; $format=[‘XXX’,’XX’,’XXXX’]; $formatted=""; foreach ($format as $cluster){ $formattedCluster=substr($string,0,strlen($cluster)); $string=substr($string,strlen($cluster)); $formatted.=$formattedCluster.’ ‘; } $formatted=substr($formatted, 0, -1); dd($formatted); //outputs: "123 45 6789" As you can see; it takes a string ..

Read more

Can someone share the solution for the format string vulnerability for the following request in laravel 8 http://domain/api?key=APIKEY&origin=3891+Delwood+Drive%2C+Powell%2C+OH%2C +United+States&destination=ZAP%25n%25s%25n%25s%25n%25s%25n%25s%25n%25s%25n%25s%25n%25s%25n%25s%25n%25s%25n%25s%25n%25s%25n%25s %25n%25s%25n%25s%25n%25s%25n%25s%25n%25s%25n%25s%25n%25s%25n%25s%0A Sourc..

Read more

I am having errors when trying to access the subscription section on my app . It’s something with the stripe API, this error occurs mostly when server caches are being cleared. I checked to clear caches, check config.app.php, payment controller, and all of that but not really understanding the source of this error! Therefore I ..

Read more

$Tag = $DOMHandler->getElementsByTagName(‘p’)->item($j)->nodeValue; $Words = preg_split(‘!s+!’, $Tag); $Tag is a normal string that I extracted from a HTML string using DOMDocument. I am using Laravel and when i use the dump and die function dd() on $Words it returns the array of characters as expected but some of the characters are binary strings. Is there ..

Read more

I have critical case, want to replace words if any of the word from given string matches. @php $stringToReplace = ‘Very Good Developer’; $stringFrom = ‘You are a Good Developer’; echo str_replace($stringToReplace, ”,$stringFrom); @endphp If for other case $strinToReplace = ‘Good sensed Developer Man’; I want to replace atleast the matched words any Matched word ..

Read more

Suppose, In title column data is stored like this $title = "We are a completely vertically integrated company which …." I want to show them into view like this <h1>We are</h1> <h2>a completely vertically</h2> <h3>integrated company which ….</h3> I split the title like this $parts = explode(" ", $title); But now, How can I join ..

Read more

I have a value in an input request that for various reason can be a string or an array. How can i make the validation rule to check that? I’ve tried the following $this->validate($request, [ ‘for’ => [‘nullable’, ‘array’, ‘string’, Rule::in($allowedVal)], ‘for.*’ => [‘nullable’, ‘string’, Rule::in($allowedVal)] ]); but not seem to work. i get "for": ..

Read more

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