public static function getAttributeValue($nodeString, $attributeName)
{
$attributeName = '[@' . $attributeName . '="';
$positionOfAttributeName = strpos($nodeString, $attributeName);
if ($positionOfAttributeName === false) {
return false;
}
$positionOfAttributeValue = $positionOfAttributeName + strlen($attributeName);
return substr($nodeString, $positionOfAttributeValue, strpos($nodeString, '"]', $positionOfAttributeValue) - $positionOfAttributeValue);
}
/** * @test */ public function returnsAttributeValueCorrectly() { $sampleNodeString = 'dateFormatLength[@type="medium"][@alt="proposed"]'; $this->assertEquals('medium', $this->model->getAttributeValue($sampleNodeString, 'type')); $this->assertEquals('proposed', $this->model->getAttributeValue($sampleNodeString, 'alt')); $this->assertEquals(false, $this->model->getAttributeValue($sampleNodeString, 'dateFormatLength')); }