L
L
livesco2018-06-26 02:16:21
PHP
livesco, 2018-06-26 02:16:21

How to turn time into seconds after parsing?

Hello everyone, I wrote a regular expression parser, it parses data from there.
And then there was one problem: the time he writes like this is 1 min 60 sec, and I need it to be 120, that is, turn it into seconds and remove the text.
I put it on the page like this
{$shows[$k]['5']}

Answer the question

In order to leave comments, you need to log in

10 answer(s)
S
Sergey, 2020-06-02
@zoonman

The following worked for me in 2020:

<a href="viber://chat?number=%2B***********">Viber</a>

Both on a PC and on a smartphone (both Android and iOS).
Where %2B is "plus", followed by a number in international format (with country code), for example %2B79876543210.

A
Andrey Skobelkin, 2021-04-22
@Skobelkin

I will add news from 2021 :)
To open a chat with the specified number, I use one link for Android and Ios, PC and MOB of this kind:

<a href="viber://chat?number=%2B79001234567">Написать в Вайбер</a>

When you click on it from a mobile or PC (the main thing is that Viber is installed), a chat with the number 79001234567 will open.
I do not recommend putting a link like this:
viber://add?number=79001230000
Since this is the code for adding a contact to the phone book. According to my tests, conversion to chat is higher when people are immediately sent to a chat link than when added to contacts.
---------------------
One more thing... But there is another option - put the CHAT-BAR widget on the site - these are links to instant messengers, social networks and phone , which open directly in applications on the phone. You can write your Call-to-action and put a link to WhatsApp, Viber, Instagram, YouTube, etc. look here https://skobelkin.ru/
Here are the advantages of the widget:
  • Widget is free
  • All links open immediately in applications on Android and iOS correctly
  • Converts mobile traffic into subscribers
  • Allows you to quickly contact the company by any means of communication

---------------------
There are link builders for Viber, choose any:
https://2hub.ru/1Umhn9M
https://2hub.ru/8kXZHzg
https: //2hub.ru/sovR7ua

P
parfenov_sk, 2017-07-02
@parfenov_sk

In the courtyard of 2017, if anyone needs more -
Open chat: Add contact: Number without a plus.

S
Siemens, 2019-08-08
@Middle_Pudge

The fact is that the Viber desktop and mobile applications open via different links, which creates certain difficulties when adding such a link to the site. Therefore, take 2 minutes to read and understand the text below) For mobile devices, this link generation approach is used:
For PC it's like this:
In order to determine the device using PHP, in the simplest case, you can use the simplest function that determines the USER_AGENT of the device, and then, depending on whether the function is ahead of the device as mobile or not, show this or that link.

<?php function check_mobile_device() { 
    $mobile_agent_array = array('ipad', 'iphone', 'android', 'pocket', 'palm', 'windows ce', 'windowsce', 'cellphone', 'opera mobi', 'ipod', 'small', 'sharp', 'sonyericsson', 'symbian', 'opera mini', 'nokia', 'htc_', 'samsung', 'motorola', 'smartphone', 'blackberry', 'playstation portable', 'tablet browser');
    $agent = strtolower($_SERVER['HTTP_USER_AGENT']);    
    foreach ($mobile_agent_array as $value) {    
        if (strpos($agent, $value) !== false) return true;   
    };     
    return false; 
};?>

You can place the function, for example, at the very beginning of the page, before 'doctype', or put it in a separate file and include it there.
After that, in the place where the link to Viber will be displayed, use the following check:
<? if(check_mobile_device()) :?>
  <a title="Viber" href="viber://add?number=79851198793"></a>              
<? else : ?>
  <a title="Viber" href="viber://chat?number=+79851198793"></a>
<? endif; ?>

Now, if a person logged in from a PC, then he will see a link for a desktop application, and if from a mobile device, then a link for a smartphone or tablet.

A
Alexander Shcherbakov, 2015-07-23
@mkll

For android, there seems to be viber://tel:xxxxxx, viber://chat:xxxxxx
but I did not check.
For iOS, there is only viber://calls(opens the tab of calls) and viber://chats(opens the tab of chats)
There is still viber://forward?text=Hello(on iOS it opens the recipient selection screen, I did not check it on Android) - from here .

D
DimanGr, 2019-11-16
@DimanGr

For the second time in a day I am convinced that there is nothing better than a cart yet.

A
An, 2014-10-12
@Flanker_4

This is called Url scheme. I am 99% sure that Viber has only made a start for the future, and at the moment this protocol only knows how to open the application (and did you check it at all?)
As for adding a contact, I doubt it very much ... security is all that, but you you can always contact support.viber.com, they will tell you. You
can also use this little thing . If the application is installed, it will throw in it, and not in the app store. Of course, here we are only talking about opening the application, and not about adding a contact.

S
staskmp, 2019-01-17
@staskmp

on iPhones and Windows, the phone format "380" does not work, you need "+380" or 068 (067, etc.)
on androids, the format with "+380" and 068 (067, etc.) does not work, you only need "380"
I HTTP_USER_AGENT I track the device
and use a regular expression to change the format,
for example, you can track it like this

<?php
 
$mobile_browser = '0';
 
if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
    $mobile_browser++;
}
 
if ((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') > 0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {
    $mobile_browser++;
}    
 
$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4));
$mobile_agents = array(
    'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
    'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
    'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
    'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
    'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
    'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
    'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
    'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
    'wapr','webc','winw','winw','xda ','xda-');
 
if (in_array($mobile_ua,$mobile_agents)) {
    $mobile_browser++;
}
    
if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini') > 0) {
    $mobile_browser++;
}
    
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows') > 0) {
    $mobile_browser = 0;
}
 
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod'))
 {
  $mobile_browser = -1;
}
   
?>

or so
<?php
 
$mobile_browser = '0';
 
if (preg_match('/(android)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
    $mobile_browser++;
}
    
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows') > 0) {
    $mobile_browser = 0;
}
 
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod'))
 {
  $mobile_browser--;
}
   
?>

and the mask can be done like this
<?php if ($mobile_browser > 0) { 
      if (substr(preg_replace('/[^0-9]/', '', $row->mobil_phone), 0, 2) != '38') { ?>
        <a href="viber://chat?number=<?php echo preg_replace('/[^0-9]/', '', substr_replace($row->mobil_phone, '38', 0, 0))?>"><?php echo preg_replace('/[^0-9+]/', '', $row->mobil_phone)?></a>
      <?php }	else { ?>
        <a href="viber://chat?number=<?php echo preg_replace('/[^0-9]/', '', $row->mobil_phone)?>"><?php echo preg_replace('/[^0-9+]/', '', $row->mobil_phone)?></a>
      <?php }?>
  <?php } else if ($mobile_browser < 0 || $mobile_browser == 0){ 
      if (substr(preg_replace('/[^0-9]/', '', $row->mobil_phone), 0, 2) != '38') { ?>
        <a href="viber://chat?number=<?php echo substr_replace(preg_replace('/[^0-9]/', '', $row->mobil_phone), '+38', 0, 0)?>"><?php echo substr_replace(preg_replace('/[^0-9]/', '', $row->mobil_phone), '+38', 0, 0)?></a>
      <?php }	else { ?>
        <a href="viber://chat?number=<?php echo substr_replace(preg_replace('/[^0-9]/', '', $row->mobil_phone), '+', 0, 0)?>"><?php echo substr_replace(preg_replace('/[^0-9]/', '', $row->mobil_phone), '+', 0, 0)?></a>
      <?php }?> 
  <?php }	?>

curve code, but working, if you optimize I will be grateful

D
d_shmn, 2019-04-24
@d_shmn

You just need to add a check from which device the user comes from. The following worked for me:

<?php
function isMobile() { 
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}
   if(isMobile()){?>
   <a href="viber://add?number=xxxxxxxxxxx">Viber</a>
   <?php
   }else{?>
      <a href="viber://chat?xxxxxxxxxxx">Viber</a>
<?php } ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question