Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
added getPlainText method to get text with trimmed tags
Browse files Browse the repository at this point in the history
  • Loading branch information
everzet committed Jun 10, 2011
1 parent 8b4e969 commit cc4d94c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Behat/Mink/Element/Element.php
Expand Up @@ -68,4 +68,30 @@ public function hasSelector($selector, $locator)
{
return null !== $this->find($selector, $locator);
}

/**
* Returns element text.
*
* @return string|null
*/
abstract public function getText();

/**
* Returns elemenelement text with trimmed tags and non-printable chars.
*
* @return string|null
*/
public function getPlainText()
{
$text = $this->getText();

if (null !== $text) {
$text = str_replace("\n", ' ', $text);
$text = preg_replace('/\<br *\/?\>/i', "\n", $text);
$text = strip_tags($text);
$text = preg_replace('/ {2,}/', ' ', $text);

return $text;
}
}
}

0 comments on commit cc4d94c

Please sign in to comment.