Jump to content

Search the Community

Showing results for tags 'formating'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hello i was having trouble creating an array with regex. I have an excel sheet with various time formats including: 1h 51m 10.5s, 51m, 10m 10.5s, 5s and I need to convert the time down to minutes. Currently my regex is as follows and does not work: /(([0-9]{1,2})h)?(([0-9]{1,2})m)?(([0-9]{1,2}\.[0-9]{0,2})s)?/ Cold any one help a noob out, Im trying to separate each segment in to an array's cell so i can manipulate it later. My code for the entire function is as follows: public function convertToMinutes($subject) { //Regular Expression to remove text $pattern = '/(([0-9]{1,2})h)?(([0-9]{1,2})m)?(([0-9]{1,2}\.[0-9]{0,2})s)?/'; $numbers = preg_split($pattern, $subject); if (empty($numbers)) { $this -> _flash('warning'); $return['errors'][] = __(sprintf('Regular Expression is wrong'), true); } else { //There are only hours, minutes and seconds if (count($numbers) == 3) { $totalMinutes = 0; $hourMinutes = $numbers[0]; $minutes = $numbers[1]; $secondMinutes = $numbers[2]; $totalMinutes = $hourMinutes / 60; $totalMinutes = $totalMinutes + ($secondMinutes * 60); $totalMinutes = $totalMinutes + ($minutes); return $totalMinutes; debug(count($numbers)); } // There is only minutes and seconds elseif (count($numbers) == 2) { $totalMinutes = 0; $minutes = $numbers[0]; $secondMinutes = $numbers[1]; $totalMinutes = $totalMinutes + ($secondMinutes * 60); $totalMinutes = $totalMinutes + ($minutes); return $totalMinutes;debug(count($numbers)); } else { //Return the minutes return $numbers[0]; } } }
×
×
  • 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.