本文整理匯總了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']);
}