How to convert a token from string to interger

We’re putting a little polish on our reports and are scripting conditional statements. Namely, if a domain name is within 30 days of renewal the line should be colored red else green.

So to check if a domain is within 30 days (do math) we need [domain.monitor.expires] to be an integer and not a string.

In this instance below $domain_expires_days prints 30 (or however many days remaining there are) but $domain_expires_days_int prints 0.

 $domain_expires_days = '[domain.monitor.expires]';
	$domain_expires_days_int = intval( $domain_expires_days ); 

Am I missing something? Thanks in advance.

Hi @lwdeddie

Try installing the Domain Monitor extension from this link:

And then try using this hook:

add_filter( 'mainwp_domain_monitor_reports_data', 'hook_mainwp_domain_monitor_reports_data', 10, 2 );
        function hook_mainwp_domain_monitor_reports_data( $data, $site_id ) {
            if ( $site_id == MY_SITE_ID ) {
                if ( is_array( $data ) && isset( $data['domain.monitor.expires'] ) ) {
                          // do something.
                          $data['domain.monitor.expires'] = SOMETHING;
            return $data;

Hi Bojan. Thanks for responding.

To be clear, I used the domain monitor example as an example but we’re trying to work with data across the pro reports spectrum. We’re running into the basic problem of all data (so far) being represented as strings only. Dates, numbers etc are all presented as strings and not their respective expected data types.

We’ve tried to convert data types so we can perform calculations or manipulations on them using functions like strtotime() and intval() but for some reason it’s not working. Not sure why.

I think we fidured it out. We were using the incorrect syntax. Evidently you cannot place an integer function in a variable like this:

$newinterger = intval($stringnumber);

it must be done like this:


THEN you can use the variable $stringnumber as an integer.

Hope this helps someone. Thanks!

I’m glad you managed to figure it out, and thanks for sharing that info with the community.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.