April 2026
Intermediate
1009 pages
34h 15m
English
Once the framework has been installed, it's time to implement it. Before we test code, we first have to produce code.[ 151 ] The functionality that searches for a URL within a string is described in Listing 36.1 and has been converted into a class (this makes the call a little easier). If a URL is found, the static UrlFinder::find() method returns it; otherwise, an exception of the type InvalidArgumentException is thrown.
<?phpclass UrlFinder { public static function find($line) { if (($start = strpos($line, "http://")) !== false) { $end1 = strpos($line, ")", $start+1); $end2 = strpos($line, " ", $start+1); if ($end1 === false && $end2 === false) { $end = strlen($line); } elseif ($end1 === false) { $end = $end2
Read now
Unlock full access