Jump to content

petrogromovo

New Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by petrogromovo

  1. Working with money in php 8 /laravel 9 site for money fields I use integer in mysql db and custom cast app/Casts/MoneyCast.php like : <?php namespace App\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class MoneyCast implements CastsAttributes { public function get($model, string $key, $value, array $attributes) { return round(floatval($value) / 100, 2); } public function set($model, string $key, $value, array $attributes) { return floatval($value) * 100; } } It seems quite good for me, but I found some referance to libraries https://github.com/brick/money and https://github.com/akaunting/laravel-money and wonder if some of which library is preferable for working in laravel ? Would it be better or safer ? Thanks in advance!
  2. Hi all, I need to make an array from string by more 1 space. I do it with code: $subject = " Line one Line Two Line Three LineLast "; $result = preg_match_all("~(.+)\b(?:[\s]{2,}|$)~U", $subject, $matches); It works, but I need to trim all elements inside of $matches : $matches = preg_replace_callback($validPattern, array($this, "trimStringValue"), $subject, limit: -1); public function trimStringValue($matches) { return trim($matches[1]); } But value of $matches after preg_replace_callback has concatanated string of all arrays in $subject, but not array of trimmed lines as I need. Why so and how that can be fixed ? Thanks in advance!
  3. Several years ago I had a good practice with regular expressions in php web pages content scraping. Last years I did not work a lot with regular expressions and lost my skills a lot. Could you please advice which kind of tasks have I to take to restore/improve my regular expressions skills out of web pages content scraping? Please examples (or links) to such tasks from your own expierence... I mean like a complete task in which regular expressions must be used...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.