本文整理汇总了PHP中Browser::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Browser::parse方法的具体用法?PHP Browser::parse怎么用?PHP Browser::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Browser
的用法示例。
在下文中一共展示了Browser::parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
<?php
include 'browser.php';
$properties = array('browser', 'browser_version', 'engine', 'engine_version', 'platform', 'platform_version', 'platform_type');
foreach ($ua_tests as $title => $test) {
if (!isset($test['ua'])) {
$test['ua'] = '';
}
$uas = is_array($test['ua']) ? $test['ua'] : array($test['ua']);
echo '<tr>';
echo '<th rowspan="' . count($uas) . '" id="' . preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $title) . '"><a href="#' . preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $title) . '">' . $title . '</a></th>';
foreach ($uas as $ua) {
if ($ua != $uas[0]) {
echo '<tr>';
}
$browser = new Browser($ua);
$browser->parse();
foreach ($properties as $property) {
if (!isset($test['test'][$property]) || $test['test'][$property] == '') {
if (empty($browser->{$property})) {
$message = 'Not tested, <b style="color:#FF0000">not found</b>';
} else {
$message = 'Not tested, found <b>' . $browser->{$property} . '</b>';
}
echo '<td style="background:#EEEEEE">' . $message . '</td>';
} elseif (strtolower($test['test'][$property]) == strtolower($browser->{$property})) {
echo '<td style="background:#00FF00">Pass (' . $browser->{$property} . ')</td>';
} else {
echo '<td style="background:#FF0000">Fail (Expected <b>' . $test['test'][$property] . '</b>, found <b>' . $browser->{$property} . '</b>)</td>';
}
}
echo '<td>' . $ua . '</td>';
示例2: assertParse
/**
* Asserts all agents in the given array match the expected name, version, system, device, engine
* and templated string.
* @param array $agents is a map of user agents to their expected values.
*/
private function assertParse($agents)
{
foreach ($agents as $agent => $values) {
$browser = Browser::parse($agent);
$this->assertEquals($values["name"], $browser->getName());
$this->assertEquals($values["system"], $browser->getSystem());
$this->assertEquals($values["device"], $browser->getDevice());
$this->assertEquals($values["version"], $browser->getVersion());
$this->assertEquals($values["engine"], $browser->getEngine());
$this->assertEquals($values["template"], $browser->forTemplate());
}
}