A member is now able to input Google|http://www.google.com (enter) Bing|http://www.bing.com (enter etc) to get nice looking links on his personal page. The output is li-ists with links: Google Bing... Now the problem is that not everyone knows how to press "|". Therefore wonder if anyone have some idea how to use for ex. ":::" or something simple. Or just retrive link name from http... The code looks like this:
<?php
// Split input string into name and url. If input is a plain link, then
// name == url. Returns link(name, url) object.
//
function split_link($input)
{
static $patterns = array
(
"@(.*?)\|(.*)@", // name|url
"@https?://.*\?.*title=(.*)(&.*)*@", // url&title=name
"@https?://.*?/(.*)@", // name from server path
"@(.*)@" // catch all
);
foreach($patterns as $key => $pattern) {
$match = array();
if(preg_match($pattern, $input, $match)) {
// print_r($match);/* uncomment for debug */
if($key == 0) {
$match['url'] = $match[2];
$match['name'] = $match[1];
} elseif($key == 3) {
$match['url'] = $match[1];
$match['name'] = $match[1];
} else {
$words = explode("|", strtr($match[1], "/-_", "|||"));
$match['url'] = $match[0];
$match['name'] = implode(" ", $words);
}
// printf("pattern %d matched %s\n", $key, $input);
// printf("name: '%s', url: '%s'\n", $match['name'], $match['url']);
break;
}
}
return (object)$match;
}
function print_links(&$arr, $max, $split)
{
printf("<ul class=\"flo-l-r\">\n");
foreach($arr as $index => $link) {
if($index >= $max) {
break;
}
if($index % $split == 0 && $index != 0) {
printf("</ul>\n");
printf("<ul class=\"flo-l-r\">\n");
}
$link = split_link($link);
printf(" <li><a rel='nofollow' target='_blank' href=\"%s\">%s</a></li>\n", $link->url, $link->name);
}
printf("</ul>\n");
}
$arr = explode("\r\n", (string)$data);
print_links($arr, 80, 4);
?>
Thanx Andy
- Text 1
- Text 2
- Text 3
etc with normal borders on the left side of each