Answer the question
In order to leave comments, you need to log in
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
The following worked for me in 2020:
<a href="viber://chat?number=%2B***********">Viber</a>
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>
viber://add?number=79001230000
In the courtyard of 2017, if anyone needs more -
Open chat:
Add contact:
Number without a plus.
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;
};?>
<? if(check_mobile_device()) :?>
<a title="Viber" href="viber://add?number=79851198793"></a>
<? else : ?>
<a title="Viber" href="viber://chat?number=+79851198793"></a>
<? endif; ?>
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 .
For the second time in a day I am convinced that there is nothing better than a cart yet.
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.
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;
}
?>
<?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--;
}
?>
<?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 } ?>
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 questionAsk a Question
731 491 924 answers to any question