本文整理汇总了PHP中Translator::getArrayFromString方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::getArrayFromString方法的具体用法?PHP Translator::getArrayFromString怎么用?PHP Translator::getArrayFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translator
的用法示例。
在下文中一共展示了Translator::getArrayFromString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTranslate
public function testTranslate()
{
$translator = new Translator();
$html = <<<HTML
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP: Hypertext Preprocessor</title>
<link rel="shortcut icon" href="http://php.net/favicon.ico">
<link rel="search" type="application/opensearchdescription+xml" href="http://php.net/phpnetimprovedsearch.src" title="Add PHP.net search">
<link rel="alternate" type="application/atom+xml" href="http://php.net/releases/feed.php" title="PHP Release feed">
<link rel="alternate" type="application/atom+xml" href="http://php.net/feed.atom" title="PHP: Hypertext Preprocessor">
<link rel="canonical" href="http://php.net/index.php">
<link rel="shorturl" href="http://php.net/index">
<link rel="alternate" href="http://php.net/index" hreflang="x-default">
</head>
<body>
<ul class="nav">
<li class=""><a href="/downloads">Downloads</a></li>
<li class=""><a href="/docs.php">Documentation</a></li>
<li class=""><a href="/get-involved" >Get Involved</a></li>
<li class=""><a href="/support">Help</a></li>
</ul>
</body>
</html>
HTML;
$array = $translator->getArrayFromString($html);
//check attributes parse
$this->assertEquals('/downloads', $array['body']['ul']['li']['0']['a']['@attributes']['href']);
//check text parse
$this->assertEquals('Documentation', $array['body']['ul']['li']['1']['a']['text']);
}