PHP Classes

File: _test.urlmatch.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of kumar mcmillan  >  urlmatch  >  _test.urlmatch.php  >  Download  
File: _test.urlmatch.php
Role: Unit test script
Content type: text/plain
Description: test script
Class: urlmatch
Matches any URLs in a string of text
Author: By
Last change: Added some new examples to detect PC/MS-DOS line breaks (see class source comments). Thanks to Ewald Frankenberger for pointing this out. Note that this is a small fix which didn't really effect the functionality of the class.
Date: 13 years ago
Size: 4,549 bytes


Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <style type="text/css">
.mainText {
    font-family: Verdana,Geneva,Helvetica; font-size: 13px; color: #999999; }
a.subclassExample:active, a.subclassExample:link, a.subclassExample:visited {
    font-family: Verdana,Geneva,Helvetica; font-size: 13px;
    color: #999999; text-decoration: underline; }
a.subclassExample:hover {
    font-family: Verdana,Geneva,Helvetica; font-size: 13px;
    color: #999999; text-decoration: none; }

<body bgcolor="#111111">
<span class="mainText" lang="en" xml:lang="en">


$url = array();
$url[] = "use this class to find a URL that appears somewhere in text.";
$url[] = "the URL can also appear as somewhere in text.";
$url[] = "it's all going to end soon, see for yourself (example of long query strings, truncated to the length you set).";
$url[] = "ahh Brighton is such a beautiful place[3-22]4+VICTORIA+ROAD,+BRIGHTON,+EN,+UK&uid=uagab4hbv2icgphc:y2haaxl47&lat=508271&lng=-1495&country=UK&level=9&style=3&width=390&height=245 (another example of an extremely long query string url)";
$url[] = "lots of subdomains -- -- right here.";
$url[] = "also does secure ( sites (in parenthesis) or typed like above";
$url[] = "also does:";
$url[] = strip_tags("example with text processed by strip_tags(): (<a target=_blank href=\"\"></a>). This is the ideal way to use the urlmatch class.");
$url[] = "same example of text with ".htmlspecialchars("<a>")." tag, unprocessed by strip_tags(): <a target=_blank href=\"\"></a>. The source is untouched, but you can't match the same url if it appears un-tagged: As a workaround, it is ideal to use strip_tags() before urlmatch() and specify the tags you want to keep.";
$url[] = "example of detection within trailing HTML tags: <p>A paragraph.</p><p>Here's a URL with trailing html tags:</p>";
$url[] = "punctuation example: Have you ever used";
$url[] = "punctuation example: Have you ever used!";
$url[] = "punctuation example: Have you ever used";
$url[] = "punctuation example: Have you ever used, then";
$url[] = "punctuation example: using; using";
$url[] = "punctuation example: Have you ever used \"\"";
$url[] = "punctuation example: Have you ever used ''";
$url[] = "punctuation example: Have you ever used (";
$url[] = "";
$url[] = "HTTP://WWW.DOPEMAN.COM";
$url[] = "current limitation of the class: can't process www urls when the same url appears in multiples with and without the url protocol (unless one of the urls has a different case): WWW.DOPEMAN.COM";
$url[] = "this works though: or";
$url[] = "this works too: duplicate urls appearing with trailing punctuation:, or,";
$url[] = "this works too: WWW.DOPEMAN.COM";
$url[] = "";
$url[] = "http://nomatch/";
$url[] = "\r\,\r\n(simulate PC line breaks)";

$u = new urlmatch();
$u->debug = FALSE;
$u->charLimit = 70;
$u->breakTxt = "...";
$u->startFromLeft = TRUE;
$num = 0;
$url as $stringWithUrl)
"<b>($num)</b> '", $u->match($stringWithUrl), "'\n<br /><br />\n\n";

$stringWithUrl = "<b>($num)</b> another example:";
$u->match($stringWithUrl,"you can also specify generic text for the matched link"),
"\n<br /><br />\n\n";