Mailinglisten-Archive |
So sieht soweit ganz gut aus. Ist zwar nicht das sch=F6nste und
sauberste, scheint aber sauber zu funktionieren :-)
Wer Verbesserungen, nur immer her damit. Wenn man fit in Regul=E4ren
Ausdr=FCcken w=E4re lie=DFe sich das ganze bestimmt auch nocheinmal ne
nummer eleganter l=F6sen.
H=E4nge jetzt einfach mal meine Version drann, die soweit ganz gut
funktioniert.
CU Markus
<?
function replace_uri($str) {
$pattern =3D
'#(^|[^\"=3D]{1})(http://|mailto:)([^\s<>]+)([\s\n<>]|$)#sm';
return preg_replace($pattern,"\\1<a
href=3D\"\\2\\3\"><u>\\2\\3</u></a>\\4",$str);
}
function sp($str, $searchTerm){
if (!is_string($searchTerm)) return 0;
if (is_array($searchTerm)) return 0;
if (!$searchTerm) return 0;
return strpos(chr(31).$str, $searchTerm);
}
function ssp($str, $searchTerm){
//this adds case insensitivity
return sp(strToLower($str), $searchTerm);
}
function add_space($str) {
$str =3D str_replace('. ', ' . ', $str);
$str =3D str_replace(', ', ' , ', $str);
$str =3D str_replace(".\n", " .\n", $str);
$str =3D str_replace(",\n", " ,\n", $str);
return $str;
}
function sub_space($str) {
$str =3D str_replace(' . ', '. ', $str);
$str =3D str_replace(' , ', ', ', $str);
$str =3D str_replace(" .\n", ".\n", $str);
$str =3D str_replace(" ,\n", ",\n", $str);
return $str;
}
function add_http($str) {
if (!ssp($str, 'www.')) return $str;
$str =3D str_replace('www.', 'http://www.', $str);
return str_replace('http://http://', 'http://', $str);
}
function add_mailto($str){
if (!sp($str, '_(at)_')) return $str;
$ar =3D explode(' ', $str);
while(list($key, $val) =3D each($ar)) {
if (sp($val, '_(at)_') && !ssp($val, 'mailto')){
$ar[$key] =3D 'mailto:' . $val;
}
}
return implode(' ', $ar);
}
function sub_http($str) {
if (!ssp($str, '>http:')) return $str;
$str =3D str_replace('>http://', '>', $str);
return $str;
};
function sub_mailto($str) {
if (!ssp($str, '>mailto:')) return $str;
$str =3D str_replace('>mailto:', '>', $str);
return $str;
};
$inhalt =3D"www.xyz.de, www.zyx.com,\n info_(at)_xyz.de\nadhoifhosd
http://www.xyz.de sdhfio";
echo $inhalt."<hr>";
$inhalt =3D add_http($inhalt);
echo $inhalt."<hr>";
$inhalt =3D add_mailto($inhalt);
$inhalt =3D add_space($inhalt);
echo $inhalt."<hr>";
$inhalt =3D replace_uri($inhalt);
$inhalt =3D sub_space($inhalt);
echo $inhalt."<hr>";
$inhalt =3D sub_http($inhalt);
echo $inhalt."<hr>";
$inhalt =3D sub_mailto($inhalt);
echo $inhalt."<hr>";
?>
php::bar PHP Wiki - Listenarchive