Pick a value from IMAP_GetMailEx

Hi

i have trouble with getting the batteristatus 8% written to a variable. How do i pick this value?

Response from „print_r ( IMAP_GetMailEx ( 50675 , ‚42602‘ ) ) ;“ looks like this:

Array
(
[ContentType] => text/plain
[CharSet] =>
[Text] =>

Dear <strong>Jan Robin Aaland</strong>,

SXXXXXXXXXXXX7

Your Nissan’s battery is 8% charged and has an estimated driving range of 17,0 km with climate control on, or 19,0 km with climate control off.

A 3kw charger will fully charge your Nissan’s battery in 16 h 0 min.

A 6kw charger will fully charge your Nissan’s battery in 7 h 30 min.
.

For more information, visit <a href=http://www.nissan.no/NO/no/YouPlus.html target=' blank'>http://www.nissan.no/NO/no/YouPlus.html</a>


(c) 2016 INFINITI

[SenderName] => 
[SenderAddress] => nissan@news-nissan.com
[Recipient] => Dilljeneve@HOTMAIL.COM
[Subject] => BATTERY STATUS
[Date] => 1638041531
[UID] => 42602
[Flags] => SEEN

I’m in a hurry, electricity prices have gone through the roof after the north sea link cable was opened. (and my wife don’t want me to spend more hours on the pc swearing and crying :grinning_face_with_smiling_eyes: :grinning_face_with_smiling_eyes:)

if this have been posted before… please point me in the right direction, my German skills are level 0

Hi Jan Robin,

Quick, dirty and not 100% tested.

$mail = IMAP_GetMailEx ( 50675 , ‚42602‘ )
$percent = get_string_between($mail['Text'] , "battery is ", "% charged and");
SetValue(12345,$percent); // write the value into an integer variable

//http://www.justin-cook.com/2006/03/31/php-parse-a-string-between-two-strings/
function get_string_between($string, $start, $end){
    $string = ' ' . $string;
    $ini = strpos($string, $start);
    if ($ini == 0) return '';
    $ini += strlen($start);
    $len = strpos($string, $end, $ini) - $ini;
    return substr($string, $ini, $len);
}

I’ll be damned :slight_smile:

Worked like a champ
an ekstra semicolon and a apostrophe gone wrong from copy/paste… but this function was exxcellent :+1:

Thanks a lot