Skip to content

Commit 83121cb

Browse files
committed
Add PHP magic method __toString for easier preg_match usage.
Feature added by https://github.com/BlaineSch
1 parent b51da69 commit 83121cb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

VerbalExpressions.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
// else
2525
// echo "invalid url";
2626

27+
// if (preg_match($regex, 'http://github.com')) {
28+
// echo 'valid url';
29+
// } else {
30+
// echo 'invalud url';
31+
// }
2732

2833
// echo "<pre>". $regex->getRegex() ."</pre>";
2934

@@ -280,6 +285,16 @@ function _or( $value ) {
280285
return $this;
281286

282287
}
288+
289+
/**
290+
* PHP Magic method to return a string representation of the object.
291+
*
292+
* @return string
293+
*/
294+
public function __toString() {
295+
return $this->getRegex();
296+
}
297+
283298
/**
284299
* Creates the final regex.
285300
* @return string The final regex

0 commit comments

Comments
 (0)