Mailinglisten-Archive |
Bei mir geht es mit
function sp($str, $searchTerm){
//this compensates a design flaw in php3
//strpos you could not distinguish between
//first position and not found
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);
}
Ich denke, sp sollte auch 0 zurückgeben könne. Siehe auch
Kommentar zu strpos im manual, wie man noch auf dies
Designproblem reagieren kann.
So kann man besser sehen, was Sache ist:
$inhalt ="www.xyz.de , www.zyx.com , info_(at)_xyz.de\nadhoifhosd
http://www.xyz.de sdhfio";
echo $inhalt."<hr>";
$inhalt = add_http(add_mailto($inhalt));
echo $inhalt."<hr>";
$inhalt = replace_uri($inhalt);
echo $inhalt."<hr>";
$inhalt = sub_http($inhalt);
echo $inhalt."<hr>";
$inhalt = sub_mailto($inhalt);
echo $inhalt."<hr>";
Kriegst du auch noch die Sache mit den Satzzeichen hin?
Markus Smigelskis schrieb am Mittwoch, 1. August 2001, 12:51:21:
> Hab jetzt mal untenstehendes fertig gemacht. Aber irgendwie klappt das
> noch nicht. Der link mit http wird ausgetauscht. die links mit www aber
> nicht.
> Und die email wird gar nicht beachtet.
> Was mache ich falsch?
> Danke Markus
> <?
> function replace_uri($str) {
> $pattern =
> '#(^|[^\"=]{1})(http://|ftp://|mailto:|news:)([^\s<>]+)([\s\n<>]|$)#sm';
> return preg_replace($pattern,"\\1<a
href=\"\\2\\3\">><u>\\2\\3</u></a>\\4",$str);
> }
> function sp($haystack, $needle, $offset=0) {
> $haystack = strtolower("$haystack");
> $needle = strtolower("$needle");
> $pos = strpos($haystack, $needle, $offset);
> if (!is_int($pos) && !$pos) {
> $pos = -1;
> }
> return $pos;
> }
> function ssp($haystack, $needle, $offset=0) {
> $pos = strpos($haystack, $needle, $offset);
> if (!is_int($pos) && !$pos) {
> $pos = -1;
> }
> return $pos;
> }
> function add_http($str) {
> if (!ssp($str, 'www.')) return $str;
> $str = str_replace('www.', 'http://www.', $str);
> return str_replace('http://http://', 'http://', $str);
> }
> function add_mailto($str){
> if (!sp($str, '_(at)_')) return $str;
> $ar = explode(' ', $str);
> while(list($key, $val) = each($ar)) {
> if (sp($val, '_(at)_') && !ssp($val, 'mailto')){
> $ar[$key] = 'mailto:' . $val;
> }
> }
> return implode(' ', $ar);
> }
> function sub_http($str) {
> if (!ssp($str, '>http:')) return $str;
> $str = str_replace('>http://', '>', $str);
> return $str;
> };
> function sub_mailto($str) {
> if (!ssp($str, '>mailto:')) return $str;
> $str = str_replace('>mailto:', '>', $str);
> return $str;
> };
> $inhalt ="www.xyz.de , www.zyx.com , info_(at)_xyz.de\nadhoifhosd
> http://www.xyz.de sdhfio";
> echo $inhalt."<br>";
> $inhalt = add_http(add_mailto($inhalt));
> echo $inhalt."<br>";
> $inhalt = replace_uri($inhalt);
> echo $inhalt."<br>";
> $inhalt = sub_http($inhalt);
> echo $inhalt."<br>";
> $inhalt = sub_mailto($inhalt);
> echo $inhalt."<br>";
?>>
--
Herzlich
Werner Stuerenburg
_________________________________________________
ISIS Verlag, Teut 3, D-32683 Barntrup-Alverdissen
Tel 0(049) 5224-997 407 · Fax 0(049) 5224-997 409
http://pferdezeitung.de
php::bar PHP Wiki - Listenarchive